Created
September 12, 2013 02:18
-
-
Save yankees714/6532434 to your computer and use it in GitHub Desktop.
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 characters
| from string import ascii_lowercase | |
| def encrypt(plain,offset): | |
| plainId = ord(plain)%97 | |
| cipherId = (plainId+offset)%26 | |
| cipher = chr(97+cipherId).upper() | |
| return cipher | |
| def encryptString(plainString,offset): | |
| cipherString = "" | |
| for letter in plainString: | |
| cipherString = cipherString + encrypt(letter,offset) | |
| return cipherString | |
| def decrypt(cipher,offset): | |
| cipher = cipher.lower() | |
| cipherId = ord(cipher)%97 | |
| plainId = cipherId - offset | |
| if plainId < 0: | |
| plainId = 26 + plainId | |
| plain = chr(97+plainId) | |
| return plain | |
| def decryptString(cipherString, offset): | |
| plainString = "" | |
| for letter in cipherString: | |
| plainString = plainString + decrypt(letter,offset) | |
| return plainString | |
| def cipherWheelWithOffset(offset): | |
| wheel = [] | |
| for letter in ascii_lowercase: | |
| wheel.append(letter + " -- " + encrypt(letter,offset)) | |
| for pair in wheel: | |
| print pair |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment