pep up code
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
def encrypt(key, plaintext):
|
||||
out=""
|
||||
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=""
|
||||
out = ""
|
||||
for i in range(0, len(cipertext)):
|
||||
pln = ord(cipertext[i])-(ord(key[i%len(key)]) - 0x61)
|
||||
pln = ord(cipertext[i])-(ord(key[i % len(key)]) - 0x61)
|
||||
pln = pln + 26 if pln < 0x61 else pln
|
||||
out += chr(pln)
|
||||
return out
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
@@ -22,11 +25,11 @@ if __name__ == "__main__":
|
||||
parser.add_argument('--out', metavar='FILE')
|
||||
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()])
|
||||
# strip non-alphabetic chars from file and convert to lower case
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user