X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/1c5994c77784086a9fc557f039afc3c03847e249..102c40aa3d705c90bbf45f491dc3f0108d583baf:/OneRoundIoT/OneRound/one_round_new.cpp?ds=sidebyside diff --git a/OneRoundIoT/OneRound/one_round_new.cpp b/OneRoundIoT/OneRound/one_round_new.cpp index b936005..b7940af 100644 --- a/OneRoundIoT/OneRound/one_round_new.cpp +++ b/OneRoundIoT/OneRound/one_round_new.cpp @@ -135,7 +135,7 @@ void prga(uchar *sc, int ldata, uchar *r) { uchar j0=0; for (int it=0; it>=8; + X[a+1]=Sbox1[mm&255]; + mm>>=8; + X[a+2]=Sbox2[mm&255]; + mm>>=8; + X[a+3]=Sbox1[mm&255]; } @@ -178,32 +184,44 @@ void encrypt_ctr(uchar* seq_in, uchar *seq_out, int len,uchar* RM1,int *Pbox, in } + for(int a=0;a>=8; + X[a+1]=X[a+1]^(mm&255); + mm>>=8; + X[a+2]=X[a+2]^(mm&255); + mm>>=8; + X[a+3]=X[a+3]^(mm&255); + } + + + + + for(int a=0;a>=8; - fX[a+1]=fX[a+1]^seq_in[ind2+a+1]^(mm&255); - mm>>=8; - fX[a+2]=fX[a+2]^seq_in[ind2+a+2]^(mm&255); - mm>>=8; - fX[a+3]=fX[a+3]^seq_in[ind2+a+3]^(mm&255); } @@ -255,9 +273,9 @@ void encrypt(uchar* seq_in, uchar *seq_out, int len,uchar* RM1, int *Pbox, int * for(int a=0;a -void decrypt(uchar* seq_in, uchar *seq_out, int len, uchar* RM1, int *Pbox, int *PboxRM, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint myrand, int debug) { +void decrypt(uchar* seq_in, uchar *seq_out, int len, uchar* RM1, int *Pbox, int *PboxRM, uchar *Sbox1, uchar *Sbox2, uchar *Inv_Sbox1, uchar *Inv_Sbox2, uint myrand, int debug) { @@ -327,9 +345,9 @@ void decrypt(uchar* seq_in, uchar *seq_out, int len, uchar* RM1, int *Pbox, int } for(int a=0;a>=8; - seq_out[ind2+a+1]=Inv_Sbox1[fX[a+1]]^(mm&255); + seq_out[ind2+a+1]=Inv_Sbox2[fX[a+1]]^(mm&255); mm>>=8; seq_out[ind2+a+2]=Inv_Sbox1[fX[a+2]]^(mm&255); mm>>=8; - seq_out[ind2+a+3]=Inv_Sbox1[fX[a+3]]^(mm&255); + seq_out[ind2+a+3]=Inv_Sbox2[fX[a+3]]^(mm&255); } @@ -654,7 +674,7 @@ int main(int argc, char** argv) { if(ctr) encrypt_ctr<4*4>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); else - decrypt<4*4>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt<4*4>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; case 8: @@ -662,7 +682,7 @@ int main(int argc, char** argv) { if(ctr) encrypt_ctr<8*8>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); else - decrypt<8*8>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt<8*8>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; case 16: @@ -670,7 +690,7 @@ int main(int argc, char** argv) { if(ctr) encrypt_ctr<16*16>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); else - decrypt<16*16>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt<16*16>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; case 32: @@ -678,7 +698,7 @@ int main(int argc, char** argv) { if(ctr) encrypt_ctr<32*32>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); else - decrypt<32*32>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt<32*32>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; case 64: @@ -686,7 +706,7 @@ int main(int argc, char** argv) { if(ctr) encrypt_ctr<64*64>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); else - decrypt<64*64>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt<64*64>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; case 128: @@ -694,7 +714,7 @@ int main(int argc, char** argv) { if(ctr) encrypt_ctr<128*128>(seq2, seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,myrand,0); else - decrypt<128*128>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Inv_Sbox1,Inv_Sbox2,myrand,0); + decrypt<128*128>(seq2,seq,len,RM1_copy,Pbox,PboxRM,Sbox1,Sbox2,Inv_Sbox1,Inv_Sbox2,myrand,0); } break; }