pep up code

breakmono2
Eggert Jung 5 years ago
parent 8078694ee0
commit 7dec1c6eb9

@ -1,9 +1,11 @@
def encrypt(key, plaintext):
out = ""
for i in range(0, len(plaintext)):
out = out + chr(((ord(key[i%len(key)])+ord(plaintext[i])-(0x61+0x61))%26)+0x61)
out += chr(((ord(key[i % len(key)]) +
ord(plaintext[i]) - (2 * 0x61)) % 26)+0x61)
return out
def decrypt(key, cipertext):
out = ""
for i in range(0, len(cipertext)):
@ -12,6 +14,7 @@ def decrypt(key, cipertext):
out += chr(pln)
return out
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
@ -23,10 +26,10 @@ if __name__ == "__main__":
args = parser.parse_args()
# strip non-alphabetic chars from file and convert to lower case
txt = ''.join([x for x in open(args.FILE, "r").read().lower() if x.isalpha()])
t = ''.join([x for x in open(args.FILE, "r").read().lower() if x.isalpha()])
if(args.encrypt != None):
print(encrypt(args.encrypt, txt))
print(encrypt(args.encrypt, t))
if(args.decrypt != None):
print(decrypt(args.decrypt, txt))
print(decrypt(args.decrypt, t))

Loading…
Cancel
Save