Skip to content

Instantly share code, notes, and snippets.

@yankees714
Created September 12, 2013 02:18
Show Gist options
  • Select an option

  • Save yankees714/6532434 to your computer and use it in GitHub Desktop.

Select an option

Save yankees714/6532434 to your computer and use it in GitHub Desktop.
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