From 56740c97f8c49847f5689f43b541994935dcbd3d Mon Sep 17 00:00:00 2001 From: Vicky Rampin Date: Sun, 24 Oct 2021 13:52:23 -0400 Subject: [PATCH] add caesar and encryption funcs --- index.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 index.py diff --git a/index.py b/index.py new file mode 100644 index 0000000..57a7253 --- /dev/null +++ b/index.py @@ -0,0 +1,36 @@ +import argparse + + +def caesar(ptextletter, keyletter): + ptextNum = ord(ptextletter) - ord('A') + keyletterNum = ord(keyletter) - ord('A') + return chr((ptextNum + keyletterNum) % 26 + ord('A')) + + +def encryption(plaintext, key): + ciphertext = '' + for i in range(len(plaintext)): + ciphertext += caesar(plaintext[i], key[i % len(key)]) + return ciphertext + + +def decryption(ciphertext, key): + return ciphertext + + +def main(): + # parse command line argument + parser = argparse.ArgumentParser() + parser.add_argument('--ptext', type=str) + parser.add_argument('--key', type=str) + args = parser.parse_args() + + key = args.key + ciphertext = encryption(args.ptext, key) + + print("Ciphertext: " + ciphertext) + print("Decrypted plaintext: " + decryption(ciphertext, key)) + + +if __name__ == '__main__': + main()