电子科技大学《现代密码学》慕课截图——感谢聂旭云、廖永建、熊虎等几位老师的讲解 | |
|
|
算法code | |
A5_1.alg program describes 128 steps of the A5/1 keystream generator which produced 128 keystream bits (with constant len). Values of registers cells at the start are encoded with Boolean variables number 1 .. 64, in particular: To construct a cryptanalysis problem one needs to add to this CNF known keystream bits via unit clauses. |
|
1 define len 128; 2 __in bit regA[19]; 3 __in bit regB[22]; 4 __in bit regC[23]; 5 __out bit result[len]; 6 7 bit shift_rslosA() 8 { 9 bit x = regA[18]; 10 bit y = regA[18]^regA[17]^regA[16]^regA[13]; 11 for(int j = 18; j > 0; j=j-1) 12 { 13 regA[j] = regA[j-1]; 14 } 15 regA[0] = y; 16 return x; 17 } 18 19 bit shift_rslosB() 20 { 21 bit x = regB[21]; 22 bit y = regB[21]^regB[20]; 23 for(int j = 21; j > 0; j=j-1) 24 { 25 regB[j] = regB[j-1]; 26 } 27 regB[0] = y; 28 return x; 29 } 30 31 bit shift_rslosC() 32 { 33 bit x = regC[22]; 34 bit y = regC[22]^regC[21]^regC[20]^regC[7]; 35 for(int j = 22; j > 0; j=j-1) 36 { 37 regC[j] = regC[j-1]; 38 } 39 regC[0] = y; 40 return x; 41 } 42 43 bit majority(bit A, bit B, bit C) 44 { 45 return A&B|A&C|B&C; 46 } 47 48 void main() 49 { 50 int midA = 8; 51 int midB = 10; 52 int midC = 10; 53 bit maj; 54 for(int i = 0; i < len; i= i + 1) 55 { 56 maj = majority(regA[midA],regB[midB],regC[midC]); 57 if(!(maj^regA[midA])) shift_rslosA(); 58 if(!(maj^regB[midB])) shift_rslosB(); 59 if(!(maj^regC[midC])) shift_rslosC(); 60 result[i] = regA[18]^regB[21]^regC[22]; 61 } 62 }
|
|
对应cnf的头部如下: | |
p cnf 8425 38262 |
|