Last active
May 27, 2024 20:52
-
-
Save jameslyons/8701593 to your computer and use it in GitHub Desktop.
Revisions
-
jameslyons revised this gist
Jan 30, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,13 +7,13 @@ # encipher ciphertext = "" for c in plaintext.upper(): if c.isalpha(): ciphertext += I2L[ (L2I[c] + key)%26 ] else: ciphertext += c # decipher plaintext2 = "" for c in ciphertext.upper(): if c.isalpha(): plaintext2 += I2L[ (L2I[c] - key)%26 ] else: plaintext2 += c -
jameslyons created this gist
Jan 30, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ # we need 2 helper mappings, from letters to ints and the inverse L2I = dict(zip("ABCDEFGHIJKLMNOPQRSTUVWXYZ",range(26))) I2L = dict(zip(range(26),"ABCDEFGHIJKLMNOPQRSTUVWXYZ")) key = 3 plaintext = "DEFEND THE EAST WALL OF THE CASTLE" # encipher ciphertext = "" for c in plaintext: if c.isalpha(): ciphertext += I2L[ (L2I[c] + key)%26 ] else: ciphertext += c # decipher plaintext2 = "" for c in ciphertext: if c.isalpha(): plaintext2 += I2L[ (L2I[c] - key)%26 ] else: plaintext2 += c print plaintext print ciphertext print plaintext2