Skip to content

Instantly share code, notes, and snippets.

@countrymarmot
Created January 6, 2014 04:11
Show Gist options
  • Save countrymarmot/8278097 to your computer and use it in GitHub Desktop.
Save countrymarmot/8278097 to your computer and use it in GitHub Desktop.
test the basic encypt method
def string_process(string, encrypt):
int_list = []
for s in string:
int_list.append(ord(s))
result = ''
for i in int_list:
if i >= ord('A') and i <= ord('z'):
if encrypt:
result += chr(i - 3)
else:
result += chr(i + 3)
else:
result += chr(i)
return result
def encrypt(string):
result = string_process(string, True)
return result
def decrypt(string):
result = string_process(string, False)
return result
if __name__ == '__main__':
string = "Ghost in the shell!"
encrypt_string = encrypt(string)
print encrypt_string
decrypt_string = decrypt(encrypt_string)
print decrypt_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment