pep up code
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
def encrypt(key, plaintext):
|
def encrypt(key, plaintext):
|
||||||
out = ""
|
out = ""
|
||||||
for i in range(0, len(plaintext)):
|
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
|
return out
|
||||||
|
|
||||||
|
|
||||||
def decrypt(key, cipertext):
|
def decrypt(key, cipertext):
|
||||||
out = ""
|
out = ""
|
||||||
for i in range(0, len(cipertext)):
|
for i in range(0, len(cipertext)):
|
||||||
@@ -12,6 +14,7 @@ def decrypt(key, cipertext):
|
|||||||
out += chr(pln)
|
out += chr(pln)
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import argparse
|
import argparse
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
@@ -23,10 +26,10 @@ if __name__ == "__main__":
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# strip non-alphabetic chars from file and convert to lower case
|
# 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):
|
if(args.encrypt != None):
|
||||||
print(encrypt(args.encrypt, txt))
|
print(encrypt(args.encrypt, t))
|
||||||
|
|
||||||
if(args.decrypt != None):
|
if(args.decrypt != None):
|
||||||
print(decrypt(args.decrypt, txt))
|
print(decrypt(args.decrypt, t))
|
||||||
|
|||||||
Reference in New Issue
Block a user