caesars_cipher_python

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 0410ea206fc7d7f65642efb4a9aa34b3fcc4c412
parent a23cddb42725f2c30ca3d95839a5656d4e384235
Author: MichaelDim02 <31562759+MichaelDim02@users.noreply.github.com>
Date:   Wed, 21 Oct 2020 10:40:26 +0000

Add files via upload
Diffstat:
Acde.py | 31+++++++++++++++++++++++++++++++
Acen.py | 31+++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/cde.py b/cde.py @@ -0,0 +1,31 @@ +# Python implementation of the Caesar cipher (decryption script)# +# MCD 2020 # +import sys + +alphabet_doubled = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] + +def decrypt(): + de_text = "" + for character in en_text: + count = 0 + for alph_car in alphabet_doubled[:26]: + count = count + 1 + if alph_car == character: + de_text = de_text + alphabet_doubled[count+value+26] + break + elif count >= 26: + de_text = de_text + character + + print(de_text) + +if( len(sys.argv) > 2 ): + value = - (int(sys.argv[1]) + 1) + en_text = sys.argv[2].lower() + try: + decrypt() + except: + print("Terminated.") +else: + print("Usage: python cde.py [VALUE] [EN_TEXT]") + print("Example: python cde.py 4 \'lipps\'") + exit(0) diff --git a/cen.py b/cen.py @@ -0,0 +1,31 @@ +# Python implementation of the Caesar cipher (encryption script) # +# MCD 2020 GPLv3 # +import sys + +alphabet_doubled = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] + +def encrypt(): + en_text = "" + for character in plain_text: + count = 0 + for alph_char in alphabet_doubled[:26]: + count = count + 1 + if alph_char == character: + en_text = en_text+ alphabet_doubled[count+value] + break + elif count >= 26: + en_text = en_text + character + + print(en_text) + +if( len(sys.argv) > 2 ): + value = int(sys.argv[1]) - 1 + plain_text = sys.argv[2].lower() + try: + encrypt() + except: + print("\nTerminated.") +else: + print("Usage: python cen.py [VALUE] [PLAIN_TEXT]") + print("Example: python cen.py 4 \'hello\'") + exit(0)