CS166
Chris Pollett
Sep. 5, 2012
A5/1 uses three shift registers
for (i = 0 ; i < 256; i++) { S[i] = i; K[i] = key[i % N]; } j = 0; for (i = 0 ; i < 256; i++) { j = (j + S[i] + K[i]) % 256; swap(S[i], S[j]); } i = 0; j = 0; //these used in keystream
i = (i + 1) % 256; j = (j + S[i]) % 256; swap(S[i], S[j]); t = (S[i] + S[j]) % 256; keystreamByte = S[t];
Exercise Ch2, 23: Consider the ciphertext QJKES REOGH GXXRE OXEO, which was generated using an affine cipher (mod 26). Determine the constants `a` and `b` and decipher the message. Hint: "t" (coded as 19) encrypts to "H" (coded as 7) and "o" (coded as 14) encrypts to "E" (coded as 4).
Solution. Using the hint, we know `a(19)+b = 7 mod 26` and `a(14)+b = 4 mod 26`. Subtracting these two equations gives `5a = 3 mod 26`. i.e., `5a = 26m + 3` for some `m` a natural number less than 26. Notice `5a = 26m + 3 = m + 3 = 0 mod 5`, so we see `m=2` works. So `a = 11` and substituting back into the equation gives `11(19) +b = 7 mod 26`. Solving for `b`, we have `b = 7 - 209 =-20 mod 26 = 6 mod 26`. Using this, we can decode the message. Starting with, `y = 11x+6 mod 26`, and solving for `x`, we get `y - 6 = 11x mod 26`. The multiplicative inverse of `11 mod 26` is a number `z` such `11z = 1 mod 26`. Now `11z = 26m + 1 = 4m+1 = 0 mod 11` and so `m=8`, giving `11z = 26(8) + 1` and `z=19`. Hence, `19(y-6) = x mod 26`. Q (coded as `16`) comes from `19(16-6)mod 26 = 8` which is i. Continuing we get: ifyou bowat allbo wlow