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