New Text Document
New Text Document
h>
#include <stdint.h>
/*************************************
* PRIVATE VARIABLES *
*************************************/
/*************************************
* FUNCTION DECLARATIONS *
*************************************/
/*************************************
* TEST VECTORS *
*************************************/
//static unsigned char Key80[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00};
uint8_t State1[8] = {0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0xe9};
//uint8_t State1[8] = {0xa1, 0xb2, 0xc3, 0xd4, 0x4e, 0xff, 0x78, 0x11};
uint8_t Key808[8] = {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80};
//uint8_t State1[8] = {0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0xe9};
//uint8_t Key808[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
//uint8_t State1[8] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
//uint8_t Key808[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
//uint8_t State1[8] = {0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80};
//uint8_t Key808[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
//uint8_t State1[8] = {0x01, 0x0f, 0x0a, 0x0b, 0x0e, 0x0c, 0x0d, 0x09};
//uint8_t Key808[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
//uint8_t State1[8] ={0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
//000A4A6DE8DB6667
//925BEDEAD4E631EB
//0909717b5d3bcfa8
//uint8_t State1[8] ={0x00, 0x0a, 0x4a, 0x6d, 0xe8, 0xdb, 0x66, 0x67};
//uint8_t Key808[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
//uint8_t Key808[10] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x10};
//uint8_t Key808[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00};
//uint8_t Key808[10] = {0x33, 0x33, 0x33, 0x33, 0x99, 0x99, 0x99, 0x99, 0x99,
0x99};
/*************************************
* PRIMARY FUNCTIONS *
*************************************/
/**
* Main method
*/
int main() {
KeyScheduleFG2(Key808,KR);
printf("\n");
printf("\n========jjjjjjjjjjj=============\n");
//Encrypt1(State1,KR);
Encrypt2(State1,KR);
Decrypt2(State1,KR);
return 0;
}
/*************************************
* HELPER FUNCTIONS *
*************************************/
/**
* Send the state through a substitution layer nibble-by-nibble
*/
uint8_t XX[2];
uint8_t XR[8];
for (i=0;i<8;i+=2)
{
XX[0]=(SBoxP[Key[i] >> 4] );
XX[1]= SBoxQ[Key[i] & 0x0F];
XX[2]= (SBoxP[Key[i+1] >> 4] );
XX[3]= SBoxQ[Key[i+1] & 0x0F];
f_fUNCTIONFG1(XX);
XR[0]=~(KeyRR[0]^KeyRR[2]);
XR[1]=~(KeyRR[1]^KeyRR[3]);
XR[2]=(XR[0]^KeyRR[2]);
XR[3]=(XR[1]^KeyRR[3]);
XR[4]=~(KeyRR[4]^XR[2]);
XR[5]=~(KeyRR[5]^XR[3]);
XR[6]=XR[4]^KeyRR[6];
XR[7]=XR[5]^KeyRR[7];
// uint8_t S1,S2,S3,S4;
uint8_t SS1,SS2,SS3,SS4;
//printf("\n ========================= \n");
//========================
// S1=XX[0];
// S2=XX[1];
// S3=XX[2];
// S4=XX[3];
//===================================
XX[0]=SBoxQ[SS1];
XX[1]=SBoxP[SS2];
XX[2]=SBoxQ[SS3];
XX[3]=SBoxP[SS4];
//-----------------------------
//==================
XX[0]=SBoxP[SS1];
XX[1]=SBoxQ[SS2];
XX[2]=SBoxP[SS3];
XX[3]=SBoxQ[SS4];
// XX[0]=S1;
// XX[1]=S2;
// XX[2]=S3;
// XX[3]=S4;
{
uint8_t i,ss,j,N=8,round=0,R=5,mi,mc,Ob1;
uint8_t XX[4];
uint8_t ciphertxt[8];
uint8_t Left1[4],Right1[4],Ogject1[4];
mi=N/2;
mc=0;
for (i = 0; i <mi; i++)
{
ciphertxt[mc]=Right1[i];
mc++;
ciphertxt[mc]=Left1[i];
mc++;
}
//=======round===
}
{
block[j]= ciphertxt[j] ;
}
//=====================
XX[0]=(SBoxP[block[0] >> 4] );
XX[1]= SBoxQ[block[0] & 0x0F];
XX[0]=(SBoxP[block[6] >> 4] );
XX[1]= SBoxQ[block[6] & 0x0F];
XX[2]= (SBoxP[block[7] >> 4] );
XX[3]= SBoxQ[block[7] & 0x0F];
f_fUNCTIONFG1(XX);
//=====================
ciphertxt[2]= ((ciphertxt[2])^ block[6]) ;
ciphertxt[3]= ((ciphertxt[3])^ block[7]) ;
//=====================
mi=N/2;
mc=mi;
for (i = 0; i <mi; i++)
{
Ob1=block[i];
block[i]=block[mc];
block[mc]=Ob1;
mc++;
}
//====================
//============================
//=============================
mi=N/2;
mc=mi;
//=====================
XX[0]=(SBoxP[block[0] >> 4] );
XX[1]= SBoxQ[block[0] & 0x0F];
XX[2]= (SBoxP[block[1] >> 4] );
XX[3]= SBoxQ[block[1] & 0x0F];
f_fUNCTIONFG1(XX);
f_fUNCTIONFG1(XX);
}
//====================
ciphertxt[j]=block[i];
ciphertxt[j+mi]=block[i1];
mi=N/2;
mc=mi;
for (i = 0; i <mi; i++)
{
Ob1=block[i];
block[i]=block[mc];
block[mc]=Ob1;
mc++;
}