📄 wnstorm.c
字号:
/* Byte valued statistics */
vcnt[inflag][val]++;
vdis[inflag][val]+=vlst[inflag][val];
/* Increase distance for other bytes */
for (i=0; i<=255; i++) vdis[inflag][i]++;
vlst[inflag][val]=0L;
cnt[inflag]+=1;
}
/*-------------------------------------------------------------------*\
| FUNCTION: taken |
| ------------------------------------------------------------------- |
| |
| Written by: Ray Arachelian on 04/09/1994 |
| Modified by: on |
| Reason for modification: |
| |
| ------------------------------------------------------------------- |
| |
| PURPOSE: See if a bit in the window is taken. |
| |
| |
| PARAMS: victim byte, bit |
| |
| RETURNS: 0 if bit is unused, 1 if taken |
| |
| |
\*-------------------------------------------------------------------*/
int taken(int vbyte, int vbit) /* Is a bit taken */
{
int k;
int collisionflag=0;
for (k=0; k<7 && !collisionflag; k++)
if (DataByte[k]==vbyte && DataBit[k]==vbit)
collisionflag=1;
return collisionflag;
}
/*-------------------------------------------------------------------*\
| FUNCTION: victimbit |
| ------------------------------------------------------------------- |
| |
| Written by: Ray Arachelian on 04/09/1994 |
| Modified by: on |
| Reason for modification: |
| |
| ------------------------------------------------------------------- |
| |
| PURPOSE: Randomly pick a victim bit to be changed by the |
| statbitfix function. |
| |
| PARAMS: victim bit, byte, and value prefrence |
| |
| RETURNS: byte in stream to change, and bit value to alter |
| |
| NOTE: This function is useful for statistics against the count |
| of bits that are 0 or 1, but not their place. |
| |
| (ie: if bit 128 is set to 1, bit 3 may be the victim, |
| while bit 128 of another byte is a more prefered victim) |
| |
\*-------------------------------------------------------------------*/
void victimbit(int *vbit, int *vbyte, int setting, int bval)
{
int collisionflag;
int i, qbit, k, q=0;
/* How long should we keep trying to find a victim? */
#define MAXVICTIMPICK 100
/* See if we can find unused bit with same value in the
stream. If so, we change that one. */
for (i=0; i<=maxchnl; i++)
if (taken(i,bval)==0 && (stream[i] & bval)!=setting )
{
*vbit=bval;
*vbyte=i;
return;
}
do
{
*vbyte=0;
collisionflag=0;
q++;
qbit=(rand() & 7);
switch (qbit)
{
case 0: *vbit = 1; break;
case 1: *vbit = 2; break;
case 2: *vbit = 4; break;
case 3: *vbit = 8; break;
case 4: *vbit = 16; break;
case 5: *vbit = 32; break;
case 6: *vbit = 64; break;
case 7: *vbit = 128; break;
}
*vbyte=(rand() % maxchnl);
collisionflag=taken(*vbyte,*vbit);
/* We want a bit whose value is different than the one we set */
if ( ((xstream[*vbyte] & (*vbit))!=0) == (setting!=0) )
collisionflag=1;
} while (collisionflag!=0 && q<MAXVICTIMPICK);
if (collisionflag)
{
*vbit=-1; *vbyte=-1;
}
return;
}
/*-------------------------------------------------------------------*\
| FUNCTION: statbitfix |
| ------------------------------------------------------------------- |
| |
| Written by: Ray Arachelian on 04/09/1994 |
| Modified by: on |
| Reason for modification: |
| |
| ------------------------------------------------------------------- |
| |
| PURPOSE: Fix bits of the random stream to give same/similar |
| statistics as infile random noise. |
| |
| PARAMS: none |
| |
| RETURNS: nothing |
| |
\*-------------------------------------------------------------------*/
void statbitfix(void)
{
int i,j, vbit, vbyte;
for (i=0; i<maxchnl; i++) /* DataByte processing loop */
for (j=1; j<=128; j=j<<1) /* DataBits processing loop */
if ((xstream[i] & j)!=(stream[i] & j))
{
/* Find a victim bit */
victimbit(&vbit,&vbyte, (stream[i] & j),j );
if (vbyte>0) /* If found */
{
/* filter victim bit to zero, then OR the old value*/
stream[vbyte]=stream[vbyte] & (255 ^ vbit);
/* set victim bit if old one was set*/
if ( (xstream[i] & j)!=0 )
stream[vbyte]=stream[vbyte] | vbit;
}
}
}
/*-------------------------------------------------------------------*\
| FUNCTION: lrotate |
| ------------------------------------------------------------------- |
| |
| Written by: Ray Arachelian on 07/14/1992 |
| Modified by: on |
| Reason for modification: |
| |
| ------------------------------------------------------------------- |
| |
| PURPOSE: Rotate a character (8 bit word) to the left. |
| |
| PARAMS: in - character to rotate |
| times - number of times to rotate the character |
| |
| RETURNS: roatated character |
| |
| NOTE: This may need to be modified on non-80x86 machines since |
| it assumes that the leftmost bit is the highest. |
| |
\*-------------------------------------------------------------------*/
unsigned char lrotate(char in, int times)
{
unsigned char ch;
int i;
collision(472);
ch = in;
for (i=0; i<=(times & 7)+1; i++)
if (ch & 128)
ch=((ch<<1) | 1);
else
ch=(ch<<1);
collision(480);
return(ch);
}
/*-------------------------------------------------------------------*\
| FUNCTION: rrotate |
| ------------------------------------------------------------------- |
| |
| Written by: Ray Arachelian on 07/14/1992 |
| Modified by: on |
| Reason for modification: |
| |
| ------------------------------------------------------------------- |
| |
| PURPOSE: Rotate a character (8 bit word) to the right. |
| |
| PARAMS: in - character to rotate |
| times - number of times to rotate the character |
| |
| RETURNS: rotated character |
| |
| NOTE: This may need to be modified on non-80x86 machines since |
| it assumes that the leftmost bit is the highest. |
| |
\*-------------------------------------------------------------------*/
unsigned char rrotate(char in, int times)
{
unsigned char ch;
int i;
collision(516);
ch = in;
for (i=0; i<=(times & 7)+1; i++)
if (ch & 1)
ch=((ch>>1) | 128);
else
ch=(ch>>1);
collision(525);
return(ch);
}
/***********************************************************************\
* *
* Display a rotating cursor to inform user that program is busy. *
* *
* This should be replaced with a rotating watch cursor/hourglass mouse *
* cursor. *
* *
\***********************************************************************/
void scanrot(void)
{
char scan[]="/-\\|";
static int rotpos;
rotpos++;
rotpos=(rotpos & 3);
printf("%c%c",scan[rotpos],8);
}
/*-------------------------------------------------------------------*\
| FUNCTION: thermometer |
| ------------------------------------------------------------------- |
| |
| Written by: Ray Arachelian on 07/14/1992 |
| Modified by: on |
| Reason for modification: |
| |
| ------------------------------------------------------------------- |
| |
| PURPOSE: Display the infile thermometer bar |
| |
| PARAMS: none |
| |
| RETURNS: nothing. |
| |
| NOTE: This function may need to be re-written for different o/s's. |
| For unix systems running on non-80x86's, you may wish to |
| change the filled character to a pound symbol, and the |
| empty character to perhaps a minus symbol, or an underline. |
| |
| Then again on unix systems, you may want to remove this |
| function entirely if you plan to pipe its output. |
| |
| On GUI based o/s's (Mac, Windows, Next, etc.) you may wish |
| use o/s calls to actually draw a thermometer window, and |
| animate it. |
| |
\*-------------------------------------------------------------------*/
void thermometer()
{
unsigned long a,i, percent;
char filled='
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -