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

📄 clocks.h

📁 MICKEY 2.0 STREAM CIPHER IMPLEMENTATION IN VISUAL C++
💻 H
字号:
/*
RTAPS[] =  {0,1,3,4,5,6,9,12,13,16,19,20,21,22,25,28,37,38,41,42,45,46,50,52,54,
			56,58,60,61,63,64,65,66,67,71,72,79,80,81,82,87,88,89,90,91,92,94,95,96,97};
*//*
int RTAPS[100] =  {1,1,0,1,1,1,1,0,0,1,0,0,1,1,0,0,1,
		           0,0,1,1,1,1,0,0,1,0,0,1,0,0,0,0,0,
				   0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,1,0,
				   1,0,1,0,1,0,1,0,1,1,0,1,1,1,1,1,0,
				   0,0,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,
				   0,1,1,1,1,1,1,0,1,1,1,1,0,0,0};
*/			
int RTAPS[100]		= {1,1,0,1,1,1,1,0,0,1,0,0,1,1,0,0,1,
				   0,0,1,1,1,1,0,0,1,0,0,1,0,0,0,0,0,
				   0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,
                  1,0,1,0,1,0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,1,0,0,
                  0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,1,1,1,1,0,0};

//	define four sequences as COMP0(1--- 98) , COMP1(1----98) , FB0(1----99) ,	//	FB1(1----99)
	
int COMP0[98] =  {0,0,0,0,1,1,0,0,0,1,0,1,1,1,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,
				  0,0,1,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,
				  0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,0,1,};

int	COMP1[98] =  {0,1,0,1,1,0,0,1,0,1,1,1,1,0,0,1,0,1,0,0,0,1,1,0,1,0,1,1,1,0,1,1,1,
				  1,0,0,0,1,1,0,1,0,1,1,1,0,0,0,0,1,0,0,0,1,0,1,1,1,0,0,0,1,1,1,1,1,
				  1,0,1,0,1,1,1,0,1,1,1,1,0,0,0,1,0,0,0,0,1,1,1,0,0,0,1,0,0,1,1,0};

	//	determines whether certain bits are complemented when
	//	used in the S feedback function 

int	FB0[100] =   {1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,1,0,0,1,1,
				  0,0,0,0,0,0,1,1,1,0,0,1,0,0,1,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,1,0,1,
				  0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,1,1,0,1,1,1,0,0,1,1,1,0,0,1,1,0,0,0};
	
int	FB1[100] =   {1,1,1,0,1,1,1,0,0,0,0,1,1,1,0,1,0,0,1,1,0,0,0,1,0,0,1,1,0,0,1,0,1,
			      1,0,0,0,1,1,0,0,0,0,0,1,1,0,1,1,0,0,0,1,0,0,0,1,0,0,1,0,0,1,0,1,1,
				  0,1,0,1,0,0,1,0,1,0,0,0,1,1,1,1,0,1,1,1,1,1,0,0,0,0,0,0,1,0,0,0,0,1};
	
	//	two alternative sets of stages into which s99 is fed back, Galois-style 

//************************************************************************************
//****************************----- CLOCK R FUNCTION -----****************************
//************************************************************************************
void CLOCK_R(int R[],int input_bit_r,int control_bit_r)
{
    int Feedback_bit;	// r_99 XOR input bit 
    int i=0,j=0;	    
	int Rdash[100];
	
	for (i=0; i<=99; i++)//initialise Rdash
	{Rdash[i]=0;}

    Feedback_bit = R[99] ^ input_bit_r;//FEEDBACK BIT GENERATION
	
	Rdash[0]=0;
	for (i=1; i<=99; i++)
	{ Rdash[i]=R[i-1]; }
	
	for (i=0; i<=99; i++)
	{
		
			if(RTAPS[i]==1)
			{
				Rdash[i]=Rdash[i] ^ Feedback_bit;
			}
		

	}


    if (control_bit_r==1)
    {   
            for (i=0; i<=99; i++)
			{
				Rdash[i] = Rdash[i] ^ R[i];
			}
	}

	for (i=1; i<=99; i++)//update R with R'
	{R[i]=Rdash[i];}
    
}


//************************************************************************************
//****************************----- CLOCK S FUNCTION -----****************************
//************************************************************************************

/* The following function clocks register S with given input and control bits */
void CLOCK_S(int S[],int input_bit_s,int control_bit_s)
{
    int s_hat[100],Sdash[100];	/* Intermediate values of the s stages */
	int Feedback_bit;      /* s_99 ^ input bit */
    int i;

	for (i=0; i<=99; i++)//initialise s_hat and Sdash
	{
		s_hat[i]=0;
		Sdash[i]=0;
	}

    Feedback_bit = S[99] ^ input_bit_s;

    for (i=1; i<=98; i++)
	{
        s_hat[i] = S[i-1] ^ ((S[i] ^ COMP0[i]) * (S[i+1] ^ COMP1[i]));
	}
	s_hat[0] = 0;
	s_hat[99] = S[98];


    
       	
		
				if (control_bit_s==0)
				{
					for (i=0; i<=99; i++)
						Sdash[i] = s_hat[i] ^ (FB0[i] * Feedback_bit);
				}

				else
				{
					for (i=0; i<=99; i++)
						Sdash[i] = s_hat[i] ^ (FB1[i] * Feedback_bit);
				}
		

			for (i=0; i<=99; i++)//update S register
			{S[i]=Sdash[i];}
    
}


//************************************************************************************
//****************************----- CLOCK KG FUNCTION -----****************************
//************************************************************************************
/* The following routine obtains a keysteam bit from the generator, which it then clocks */
void CLOCK_KG(int R[],int S[],int mixing, int input_bit)
{
	int Control_bit_R, Control_bit_S;
	/* Control the variable clocking of the R and S registers */

	Control_bit_R = S[34] ^ R[67];
	Control_bit_S = S[67] ^ R[33];
    
	if (mixing)
	
		CLOCK_R (R, input_bit ^ S[50], Control_bit_R);
	
	else
		CLOCK_R (R, input_bit, Control_bit_R);

		CLOCK_S (S, input_bit, Control_bit_S);
}

⌨️ 快捷键说明

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