G, x, y = egcd ( a, m ) if g != 1 : raise Exception ( 'modular inverse does not exist' ) else : return x % m def letter_to_number ( c ): return ord ( c.
def egcd ( a, b ): if a = 0 : return ( b, 0, 1 ) else : g, y, x = egcd ( b % a, a ) return ( g, x - ( b // a ) * y, y ) def modinv ( a, m ): a = a % m # allows this to work with negative numbers I wrote a python script which can perform affine cipher encryptions/decryptions. Lewis Carroll wrote this in one of his poems. Given that we possess the key, we can decrypt this directly:įIRSTTHESENTENCEANDTHENTHEEVIDENCESAIDTHEQUEENĢ. This solution is verified as correct by the official Solutions for Odd-Numbered Questions manual.ġ.
This problem deals with the affine cipher with the key parameters a = 7, b = 22.įalszztysyjzyjkywjrztyjztyynaryjkyswarztyegyyj
Cryptography understanding-cryptography even-numbered-solutions