Skip to content

Instantly share code, notes, and snippets.

@QuanSai
Created October 2, 2012 18:35
Show Gist options
  • Save QuanSai/3822148 to your computer and use it in GitHub Desktop.
Save QuanSai/3822148 to your computer and use it in GitHub Desktop.
BC homework assignment
def encrypt(character, password): #takes one character, one password string
result = (int(character) % len(password)) - ord('a') #encryption operation
return result
def convert(password): #takes one password string
u_list = [ord(x) for x in password] #for each character in the password, get its ordinal version; unicode each character
result = [] #this will hold each character that's converted
for i in u_list: #for each character i in the unicoded character list
conversion = encrypt(i, password) #convert the current character i using the encryption algorithm
if conversion >= 127: #if the resulting encrypted value is greater or equal to 127,
conversion - 127 + 32 #then subtract 127 from it and add 32
result.append(chr(abs(conversion))) #append the absolute value of the converted character to the list of converted characters
return ''.join(result) #return a string; change the list of converted characters to one string
"""Test out the conversion above"""
print convert('Abort mission. Return home immediately.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment