Cryptography - Sage
Cryptography - Sage
Cryptography - Sage
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
sage: X = pt.frequency_distribution()sage: m = 11sage: r = 0.75sage: match = [ [] for i in range(m) ]sage: for i in range(m):... Z = ct[i::m].frequency_distribution()... Y = DiscreteRandomVariable(X,Z.function())... for j in range(26):... K = S([ (j+k)%26 for i in range(26) ])... corr = X.translation_correlation(Y,E(K))... if corr > r:... match[i].append(j)Solution. We have already surmised that the first sample ciphertext, cipher01.txt, isoutput from a Vigenére cipher of period 11. We the definitions as below:sage: S = AlphabeticStrings()sage: E = SubstitutionCryptosystem(S)sage: pt = S.encoding(open("Plaintext/blackcat.txt").read())sage: ct = S.encoding(open("Ciphertext/cipher01.txt").read())the output of the above code givessage: match[[], [7], [0], [], [], [18], [3], [4], [0], [], [4]]A translation by 7 corresponds to the character H, by 0 to A, by 18 to S, and by 3 and 4to Dand E, respectively. This gives the partial enciphering key *HA**SDEA*E. Decipheringwith respect to this key gives the plaintext blocks *HE**OETI*I, *KT**NPOM*N, etc.Relaxing the bound from r = 0.75 to 0.50, one finds multiple solutions among them thecorrect solution SHAKESPEARE, giving the plaintextWHENMOSTIWINKTHENDOMINEEYESBESTSEEFORALLTHEDAYTHEYVIEWTHINGSUNRESPWhy is this a bad key choice?Exercise 3.7 (Breaking substitution ciphers) Suppose that rather than an affinetranslation, you have reduced to an arbitrary simple substitution. We need to undo an109