add decryption func
This commit is contained in:
parent
56740c97f8
commit
bc4d05361c
18
index.py
18
index.py
|
@ -7,6 +7,11 @@ def caesar(ptextletter, keyletter):
|
||||||
return chr((ptextNum + keyletterNum) % 26 + ord('A'))
|
return chr((ptextNum + keyletterNum) % 26 + ord('A'))
|
||||||
|
|
||||||
|
|
||||||
|
def caesar_reverse(ptextletter, keyletter):
|
||||||
|
ptextNum = ord(ptextletter) - ord('A')
|
||||||
|
keyletterNum = ord(keyletter) - ord('A')
|
||||||
|
return chr((ptextNum - keyletterNum) % 26 + ord('A'))
|
||||||
|
|
||||||
def encryption(plaintext, key):
|
def encryption(plaintext, key):
|
||||||
ciphertext = ''
|
ciphertext = ''
|
||||||
for i in range(len(plaintext)):
|
for i in range(len(plaintext)):
|
||||||
|
@ -15,21 +20,24 @@ def encryption(plaintext, key):
|
||||||
|
|
||||||
|
|
||||||
def decryption(ciphertext, key):
|
def decryption(ciphertext, key):
|
||||||
return ciphertext
|
plaintext = ''
|
||||||
|
for i in range(len(ciphertext)):
|
||||||
|
plaintext += caesar_reverse(ciphertext[i], key[i % len(key)])
|
||||||
|
return plaintext
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# parse command line argument
|
# parse command line argument
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--ptext', type=str)
|
parser.add_argument('--text', type=str)
|
||||||
parser.add_argument('--key', type=str)
|
parser.add_argument('--key', type=str)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
key = args.key
|
key = args.key
|
||||||
ciphertext = encryption(args.ptext, key)
|
user_text = args.text
|
||||||
|
|
||||||
print("Ciphertext: " + ciphertext)
|
print("Ciphertext: " + encryption(user_text, key))
|
||||||
print("Decrypted plaintext: " + decryption(ciphertext, key))
|
print("Decrypted plaintext: " + decryption(user_text, key))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue