⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wnstorm.c

📁 数据隐藏程序
💻 C
📖 第 1 页 / 共 3 页
字号:
}




/*-------------------------------------------------------------------*\
| FUNCTION: collision                                                 |
| ------------------------------------------------------------------- |
|                                                                     |
| Written  by: Ray Arachelian   on 04/09/1994                         |
| Modified by:                  on                                    |
| Reason for modification:                                            |
|                                                                     |
| ------------------------------------------------------------------- |
|                                                                     |
| PURPOSE: Check for a bit collision, or other error.                 |
|          Used for debugging.                                        |
|                                                                     |
| PARAMS:  line number to display in error message.                   |
|                                                                     |
| RETURNS: nothing.                                                   |
|                                                                     |
|                                                                     |
\*-------------------------------------------------------------------*/



void collision(int line)
{

 unsigned i, j;

if (limitchnl<2 || limitchnl>32)
  {
  printf("limitchnl out of range in line %d (max=%d, lim=%d)\n",
				line,maxchnl,limitchnl);
  }



 j=0;

 for (i=0; i<=7; i++)
   j=j^DataBit[i];

 if (j!=255)
 {
  printf("\7\7Data bit collision in line %d\n\r",line);

  for (i=0; i<=7; printf("Bit %d = %d, \n\r",i,DataBit[i]),i++);

  printf("\n\r");

  exit(0);
 }


}




/*-------------------------------------------------------------------*\
| FUNCTION: getrand                                                   |
| ------------------------------------------------------------------- |
|                                                                     |
| Written  by: Ray Arachelian   on 04/09/1994                         |
| Modified by:                  on                                    |
| Reason for modification:                                            |
|                                                                     |
| ------------------------------------------------------------------- |
|                                                                     |
| PURPOSE: Returns a random value, either from a random file,         |
|          random number device, or random number function.           |
|                                                                     |
| PARAMS:  none                                                       |
|                                                                     |
| RETURNS: random value (char)                                        |
|                                                                     |
|                                                                     |
\*-------------------------------------------------------------------*/


char getrand(void)
{

 rndread++;

 if (rndfile==NULL) return (char) (rand() & 0xff);

 if (rsize!=MAXLONG) rsize--;

 if (rsize<1)
  {
   fcloseall();
   perror("\n\7\7\7!!!END OF RANDOM FILE REACHED BEFORE ENCRYPTION COMPLETED!!!\n");
   getch();
   exit(-99);
  }

 return (fgetc(rndfile));
}



/*-------------------------------------------------------------------*\
| FUNCTION: statistics                                                |
| ------------------------------------------------------------------- |
|                                                                     |
| Written  by: Ray Arachelian   on 04/09/1994                         |
| Modified by:                  on                                    |
| Reason for modification:                                            |
|                                                                     |
| ------------------------------------------------------------------- |
|                                                                     |
| PURPOSE: Keep statistical information of incoming random            |
|          data and outgoing random data to the stream. 	      |
|                                                                     |
| PARAMS:  mode, invalue                                              |
|                                                                     |
| RETURNS: nothing.                                                   |
|                                                                     |
| NOTE:    This function should be replaced by a better one that      |
|          does more analysis than this one.                          |
|                                                                     |
\*-------------------------------------------------------------------*/

void statistics(int inflag, int val)
{
 static float cnt[2];     /* Count of values              */
 static float sum[2];     /* Sum of all numbers           */
 static float ssum[2];    /* Sum of squares of numbers    */
 static float bit0[2];    /* Total bits off               */
 static float bit1[2];    /* Total bits on                */
 static float bcn1[2][8]; /* count of 1 bits individually */
 static float bcn0[2][8]; /* count of 0 bits individually */


 static long  vcnt[2][256]; /* byte value counts          */
 static long  vdis[2][256]; /* byte value distance        */
 static long  vlst[2][256]; /* byte value last            */


 /* Closeness of bits of same type */

 static float b0d[2];     /* bit zero distance            */
 static float b1d[2];     /* bit one distance             */
 static float b0c[2];     /* bit zero count               */
 static float b1c[2];     /* bit one count                */
 static int lastone, lastzero;

 float  average;
 float  variance;
 float  bit0ave, bit1ave;


 int i,j;


 if (inflag==-1) /* Reset statistics */
  {
    sum[0]=0.0;
   ssum[0]=0.0;
   bit0[0]=0.0;
   bit1[0]=0.0;
    sum[1]=0.0;
   ssum[1]=0.0;
   bit0[0]=0.0;
   bit1[0]=0.0;

   b0d[0]=0.0;
   b1d[0]=0.0;
   b0c[0]=0.0;
   b1c[0]=0.0;

   b0d[1]=0.0;
   b1d[1]=0.0;
   b0c[1]=0.0;
   b1c[1]=0.0;

   for (i=0; i<7; i++)
    {bcn1[0][i]=0.0;
     bcn1[1][i]=0.0;
     bcn0[0][i]=0.0;
     bcn0[1][i]=0.0;
    }

   for (i=0; i<=255; i++)
    {
     vcnt[0][i]=0L; /* byte value counts          */
     vdis[0][i]=0L; /* byte value distance        */
     vlst[0][i]=0L; /* byte value last            */
     vcnt[1][i]=0L; /* byte value counts          */
     vdis[1][i]=0L; /* byte value distance        */
     vlst[1][i]=0L; /* byte value last            */
    }
    lastone=0;
    lastzero=0;


   return;
  }

 if (inflag==-2) /* Display stats */
  {



  puts("");
  puts("---------------------------------------------------------------");
  puts("        Statistical Incoming Random Number Report:");
  puts("---------------------------------------------------------------");
  puts("");
  printf("Number of incoming values     : %f\n",cnt[0]);
  printf("Sum of incoming values        : %f\n",sum[0]);
  printf("Sum of squared incoming values: %f\n",ssum[0]);


  if (cnt[0]!=0.0)  /* Prevent divide by zero */
  {
  average= (sum[0]/cnt[0]);
  variance=(ssum[0])-(average*average);  /* Not too sure of this!*/
  variance=variance/cnt[0];

  printf("Average incoming value        : %f\n",average);
  printf("Variance of incoming values   : %f\n",variance);
  }

  bit0ave=b0d[0]/b0c[0];
  bit1ave=b1d[0]/b1c[0];

  printf("Ave dist bit=0 to next bit=0  : %f\n",bit0ave);
  printf("Ave dist bit=1 to next bit=1  : %f\n",bit1ave);

  printf("Count of all bits set to zero : %f\n",bit0[0]);
  printf("Count of all bits set to one  : %f\n",bit1[0]);

  for (i=0; i<=7; i++)
     printf("Count of bit %d set to 0/1  : %f/%f\n",i,bcn0[0][i],bcn1[0][i]);

  puts("");
  puts("");

  puts("<MORE>");
  getch();  /* Wait for a keypress */

  puts("");
  puts("---------------------------------------------------------------");
  puts("        Statistical Outgoming Random Number Report:");
  puts("---------------------------------------------------------------");
  puts("");

  printf("Statistical bit fixing mode   : ");
  if (bitfix) puts("On"); else puts("Off");

  printf("Number of outgoing values     : %f\n",cnt[1]);
  printf("Sum of outgoing values        : %f\n",sum[1]);
  printf("Sum of squared outgoing values: %f\n",ssum[1]);


  if (cnt[1]!=0.0)  /* Prevent divide by zero */
  {
  average= (sum[1]/cnt[1]);
  variance=(ssum[1])-(average*average);  /* Not too sure of this!*/
  variance=variance/cnt[1];

  printf("Average outgoing value        : %f\n",average);
  printf("Variance of outgoing values   : %f\n",variance);
  }

  bit0ave=b0d[1]/b0c[1];
  bit1ave=b1d[1]/b1c[1];

  printf("Ave dist bit=0 to next bit=0  : %f\n",bit0ave);
  printf("Ave dist bit=1 to next bit=1  : %f\n",bit1ave);


  printf("Count of all bits set to zero : %f\n",bit0[1]);
  printf("Count of all bits set to one  : %f\n",bit1[1]);

  for (i=0; i<=7; i++)
     printf("Count of bit %d set to 0/1  : %f/%f\n",i,bcn0[1][i],bcn1[1][i]);

  puts("");
  puts("");

  puts("<MORE>");
  getch();


  puts("");
  puts("---------------------------------------------------------------");
  puts("     Statistical Byte Value Distance / Frequency Report:");
  puts("---------------------------------------------------------------");
  puts("");

  puts("Value         InCount InAveDist OutCount OutAveDist");
  puts("---------------------------------------------------------------");

  for (i=0; i<=255; i++)
  {
   printf("%8d   %8ld %8ld %8ld %8ld\n",i,
	  vcnt[0][i],(long) (vdis[0][i]/vcnt[0][i]),
	  vcnt[1][i],(long) (vdis[1][i]/vcnt[1][i]));

   if ((i & 15)==15) {puts("<MORE>"); getch();};

  }


  puts("");
  return;
  }

   sum[inflag]+=val;           /* Sum         */
  ssum[inflag]+=(val*val);     /* Squared sum */


  /* Bit statistics */

  for (i=1,j=0; j<=7; j++,i=i*2)
    if ((val & i)!=0)
     { bcn1[inflag][j] +=1;       bit1[inflag]+=1;
       b1d[inflag]+=lastone;
       b1c[inflag]+=1;
       lastzero++;
       lastone=0;
     }
    else
     { bcn0[inflag][j] +=1;       bit0[inflag]+=1;
       b0d[inflag]+=lastzero;
       b0c[inflag]+=1;
       lastone++;
       lastzero=0;
     }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -