Created
January 6, 2014 04:11
-
-
Save countrymarmot/8278097 to your computer and use it in GitHub Desktop.
test the basic encypt method
This file contains 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
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