shorten code
This commit is contained in:
@@ -8,9 +8,8 @@ def decrypt(key, cipertext):
|
||||
out=""
|
||||
for i in range(0, len(cipertext)):
|
||||
pln = ord(cipertext[i])-(ord(key[i%len(key)]) - 0x61)
|
||||
if pln < 0x61:
|
||||
pln = pln + 26
|
||||
out = out + chr(pln)
|
||||
pln = pln + 26 if pln < 0x61 else pln
|
||||
out += chr(pln)
|
||||
return out
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -21,14 +20,10 @@ if __name__ == "__main__":
|
||||
command_group.add_argument('--encrypt', metavar='KEY')
|
||||
command_group.add_argument('--decrypt', metavar='KEY')
|
||||
parser.add_argument('--out', metavar='FILE')
|
||||
|
||||
args = parser.parse_args()
|
||||
fd = open(args.FILE, "r")
|
||||
txt_in = fd.read()
|
||||
txt = ""
|
||||
for i in txt_in.lower():
|
||||
if i.isalpha():
|
||||
txt = txt + i
|
||||
|
||||
#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()])
|
||||
|
||||
if(args.encrypt != None):
|
||||
print(encrypt(args.encrypt, txt))
|
||||
|
||||
Reference in New Issue
Block a user