lower ()) - ord ( 'a' ) def number_to_letter ( n ): return chr ( n % 26 + ord ( 'a' )) def affine_encrypt ( a, b, plaintext ): def encrypt_letter ( c ): n = letter_to_number ( c ) return number_to_letter (( a * n + b ) % 26 ) return "". 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
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |