add caesar and encryption funcs
This commit is contained in:
parent
567a719f54
commit
56740c97f8
|
@ -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()
|
Loading…
Reference in New Issue