From d24a54dd88ef3e027265c1a19cda3997faa77cf1 Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:34:06 +0530 Subject: [PATCH 01/13] create monoalphabetic cipher --- ciphers/mono_alphabetic_ciphers.py | 82 ++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 ciphers/mono_alphabetic_ciphers.py diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py new file mode 100644 index 000000000000..43440163ef76 --- /dev/null +++ b/ciphers/mono_alphabetic_ciphers.py @@ -0,0 +1,82 @@ +LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + + +def main(): + myMessage = "When you do the common things in life in an uncommon way, you will command the attention of the world" + myKey = "QWERTYUIOPASDFGHJKLZXCVBNM" + myMode = "decrypt" # set to 'encrypt' or 'decrypt' + + checkValidKey(myKey) + + if myMode == "encrypt": + translated = encryptMessage(myKey, myMessage) + elif myMode == "decrypt": + translated = decryptMessage(myKey, myMessage) + print('Using key %s' % (myKey)) + print('The %sed message is:' % (myMode)) + print(translated) + + +def checkValidKey(key: str): + keyList = list(key) + lettersList = list(LETTERS) + keyList.sort() + lettersList.sort() + if keyList != lettersList: + sys.exit('There is an error in the key or symbol set.') + + +def encryptMessage(key: str, message: str) -> str: + """ + >>> encryptMessage("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world") + 'Vitf ngx rg zit egddgf zioful of soyt of qf xfegddgf vqn, ngx voss egddqfr zit qzztfzogf gy zit vgksr' + """ + return translateMessage(key, message, "encrypt") + + +def decryptMessage(key, message): + """ + >>> decryptMessage("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world") + 'Bpcy fig mi epc vizziy ephyol hy shnc hy ky gyvizziy bkf, fig bhss vizzkym epc keecyehiy in epc bidsm' + """ + return translateMessage(key, message, "decrypt") + + +def translateMessage(key, message, mode): + """ + >>> translateMessage("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world", "encrypt") + 'Vitf ngx rg zit egddgf zioful of soyt of qf xfegddgf vqn, ngx voss egddqfr zit qzztfzogf gy zit vgksr' + """ + translated = '' + charsA = LETTERS + charsB = key + if mode == 'decrypt': + # For decrypting, we can use the same code as encrypting. We + # just need to swap where the key and LETTERS strings are used. + charsA, charsB = charsB, charsA + # loop through each symbol in the message + for symbol in message: + if symbol.upper() in charsA: + # encrypt/decrypt the symbol + symIndex = charsA.find(symbol.upper()) + if symbol.isupper(): + translated += charsB[symIndex].upper() + else: + translated += charsB[symIndex].lower() + else: + # symbol is not in LETTERS, just add it + translated += symbol + return translated + + +def getRandomKey(): + key = list(LETTERS) + random.shuffle(key) + return ''.join(key) + + +if __name__ == '__main__': + import doctest + + doctest.testmod() + main() From 949790a0730227f465c1794e145d076809896959 Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:45:08 +0530 Subject: [PATCH 02/13] update file --- ciphers/mono_alphabetic_ciphers.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index 43440163ef76..be5fe100d0be 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -68,13 +68,6 @@ def translateMessage(key, message, mode): translated += symbol return translated - -def getRandomKey(): - key = list(LETTERS) - random.shuffle(key) - return ''.join(key) - - if __name__ == '__main__': import doctest From ac8495340cb351d6eb70308838d83cc7469e9ac3 Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:49:03 +0530 Subject: [PATCH 03/13] update file --- ciphers/mono_alphabetic_ciphers.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index be5fe100d0be..ebd2cc5e6571 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -1,4 +1,4 @@ -LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" def main(): @@ -12,8 +12,8 @@ def main(): translated = encryptMessage(myKey, myMessage) elif myMode == "decrypt": translated = decryptMessage(myKey, myMessage) - print('Using key %s' % (myKey)) - print('The %sed message is:' % (myMode)) + print("Using key %s" % (myKey)) + print("The %sed message is:" % (myMode)) print(translated) @@ -23,7 +23,7 @@ def checkValidKey(key: str): keyList.sort() lettersList.sort() if keyList != lettersList: - sys.exit('There is an error in the key or symbol set.') + sys.exit("There is an error in the key or symbol set.") def encryptMessage(key: str, message: str) -> str: @@ -47,10 +47,10 @@ def translateMessage(key, message, mode): >>> translateMessage("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world", "encrypt") 'Vitf ngx rg zit egddgf zioful of soyt of qf xfegddgf vqn, ngx voss egddqfr zit qzztfzogf gy zit vgksr' """ - translated = '' + translated = "" charsA = LETTERS charsB = key - if mode == 'decrypt': + if mode == "decrypt": # For decrypting, we can use the same code as encrypting. We # just need to swap where the key and LETTERS strings are used. charsA, charsB = charsB, charsA @@ -68,7 +68,8 @@ def translateMessage(key, message, mode): translated += symbol return translated -if __name__ == '__main__': + +if __name__ == "__main__": import doctest doctest.testmod() From 7d41624b2ef88ca47a5e11515e1ac0da05cd6b8f Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:17:36 +0530 Subject: [PATCH 04/13] update file --- ciphers/mono_alphabetic_ciphers.py | 86 +++++++++++++++--------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index ebd2cc5e6571..e1f5a5c66d3b 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -1,50 +1,9 @@ LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" -def main(): - myMessage = "When you do the common things in life in an uncommon way, you will command the attention of the world" - myKey = "QWERTYUIOPASDFGHJKLZXCVBNM" - myMode = "decrypt" # set to 'encrypt' or 'decrypt' - - checkValidKey(myKey) - - if myMode == "encrypt": - translated = encryptMessage(myKey, myMessage) - elif myMode == "decrypt": - translated = decryptMessage(myKey, myMessage) - print("Using key %s" % (myKey)) - print("The %sed message is:" % (myMode)) - print(translated) - - -def checkValidKey(key: str): - keyList = list(key) - lettersList = list(LETTERS) - keyList.sort() - lettersList.sort() - if keyList != lettersList: - sys.exit("There is an error in the key or symbol set.") - - -def encryptMessage(key: str, message: str) -> str: - """ - >>> encryptMessage("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world") - 'Vitf ngx rg zit egddgf zioful of soyt of qf xfegddgf vqn, ngx voss egddqfr zit qzztfzogf gy zit vgksr' - """ - return translateMessage(key, message, "encrypt") - - -def decryptMessage(key, message): - """ - >>> decryptMessage("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world") - 'Bpcy fig mi epc vizziy ephyol hy shnc hy ky gyvizziy bkf, fig bhss vizzkym epc keecyehiy in epc bidsm' - """ - return translateMessage(key, message, "decrypt") - - -def translateMessage(key, message, mode): +def translate_message(key, message, mode): """ - >>> translateMessage("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world", "encrypt") + >>> translate_message("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world", "encrypt") 'Vitf ngx rg zit egddgf zioful of soyt of qf xfegddgf vqn, ngx voss egddqfr zit qzztfzogf gy zit vgksr' """ translated = "" @@ -69,6 +28,47 @@ def translateMessage(key, message, mode): return translated +def encrypt_message(key: str, message: str) -> str: + """ + >>> encrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world") + 'Vitf ngx rg zit egddgf zioful of soyt of qf xfegddgf vqn, ngx voss egddqfr zit qzztfzogf gy zit vgksr' + """ + return translate_message(key, message, "encrypt") + + +def decrypt_message(key, message): + """ + >>> decrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world") + 'Bpcy fig mi epc vizziy ephyol hy shnc hy ky gyvizziy bkf, fig bhss vizzkym epc keecyehiy in epc bidsm' + """ + return translate_message(key, message, "decrypt") + + +def check_validKey(key: str): + keyList = list(key) + lettersList = list(LETTERS) + keyList.sort() + lettersList.sort() + if keyList != lettersList: + sys.exit("There is an error in the key or symbol set.") + + +def main(): + myMessage = "When you do the common things in life in an uncommon way, you will command the attention of the world" + myKey = "QWERTYUIOPASDFGHJKLZXCVBNM" + myMode = "decrypt" # set to 'encrypt' or 'decrypt' + + check_validKey(myKey) + + if myMode == "encrypt": + translated = encrypt_message(myKey, myMessage) + elif myMode == "decrypt": + translated = decrypt_message(myKey, myMessage) + print("Using key %s" % (myKey)) + print("The %sed message is:" % (myMode)) + print(translated) + + if __name__ == "__main__": import doctest From 5019b82ef680cb29e46592c132abf72c4d897006 Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:23:16 +0530 Subject: [PATCH 05/13] update file --- ciphers/mono_alphabetic_ciphers.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index e1f5a5c66d3b..eef153babf1e 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -44,22 +44,11 @@ def decrypt_message(key, message): return translate_message(key, message, "decrypt") -def check_validKey(key: str): - keyList = list(key) - lettersList = list(LETTERS) - keyList.sort() - lettersList.sort() - if keyList != lettersList: - sys.exit("There is an error in the key or symbol set.") - - def main(): myMessage = "When you do the common things in life in an uncommon way, you will command the attention of the world" myKey = "QWERTYUIOPASDFGHJKLZXCVBNM" myMode = "decrypt" # set to 'encrypt' or 'decrypt' - check_validKey(myKey) - if myMode == "encrypt": translated = encrypt_message(myKey, myMessage) elif myMode == "decrypt": From 4ff85e56e1885e227bcc22d1f6151d90793b2bf5 Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:39:58 +0530 Subject: [PATCH 06/13] update file --- ciphers/mono_alphabetic_ciphers.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index eef153babf1e..50259bdc5629 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -3,16 +3,15 @@ def translate_message(key, message, mode): """ - >>> translate_message("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world", "encrypt") + >>> translate_message( + "QWERTYUIOPASDFGHJKLZXCVBNM", + "When you do the common things in life in an uncommon way, " + "you will command the attention of the world", "encrypt") 'Vitf ngx rg zit egddgf zioful of soyt of qf xfegddgf vqn, ngx voss egddqfr zit qzztfzogf gy zit vgksr' """ + charsA = LETTERS if mode == "decrypt" else key + charsB = key if mode == "decrypt" else LETTERS translated = "" - charsA = LETTERS - charsB = key - if mode == "decrypt": - # For decrypting, we can use the same code as encrypting. We - # just need to swap where the key and LETTERS strings are used. - charsA, charsB = charsB, charsA # loop through each symbol in the message for symbol in message: if symbol.upper() in charsA: @@ -45,7 +44,10 @@ def decrypt_message(key, message): def main(): - myMessage = "When you do the common things in life in an uncommon way, you will command the attention of the world" + myMessage = ( + "When you do the common things in life in an uncommon way, " + "you will command the attention of the world" + ) myKey = "QWERTYUIOPASDFGHJKLZXCVBNM" myMode = "decrypt" # set to 'encrypt' or 'decrypt' From 8429a56c491ec498c2ffaccdee466b50974469de Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:07:30 +0530 Subject: [PATCH 07/13] update after testing flake8 on this code --- ciphers/mono_alphabetic_ciphers.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index 50259bdc5629..d6bc79995b4e 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -4,10 +4,10 @@ def translate_message(key, message, mode): """ >>> translate_message( - "QWERTYUIOPASDFGHJKLZXCVBNM", - "When you do the common things in life in an uncommon way, " - "you will command the attention of the world", "encrypt") - 'Vitf ngx rg zit egddgf zioful of soyt of qf xfegddgf vqn, ngx voss egddqfr zit qzztfzogf gy zit vgksr' + "QWERTYUIOPASDFGHJKLZXCVBNM", + "Hello World!", + "encrypt") + 'Pcssi Bidsm' """ charsA = LETTERS if mode == "decrypt" else key charsB = key if mode == "decrypt" else LETTERS @@ -29,25 +29,22 @@ def translate_message(key, message, mode): def encrypt_message(key: str, message: str) -> str: """ - >>> encrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world") - 'Vitf ngx rg zit egddgf zioful of soyt of qf xfegddgf vqn, ngx voss egddqfr zit qzztfzogf gy zit vgksr' + >>> encrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World!") + 'Pcssi Bidsm' """ return translate_message(key, message, "encrypt") -def decrypt_message(key, message): +def decrypt_message(key: str, message: str) -> str: """ - >>> decrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "When you do the common things in life in an uncommon way, you will command the attention of the world") - 'Bpcy fig mi epc vizziy ephyol hy shnc hy ky gyvizziy bkf, fig bhss vizzkym epc keecyehiy in epc bidsm' + >>> decrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World!") + 'Itssg Vgksr' """ return translate_message(key, message, "decrypt") def main(): - myMessage = ( - "When you do the common things in life in an uncommon way, " - "you will command the attention of the world" - ) + myMessage = "Hello World!" myKey = "QWERTYUIOPASDFGHJKLZXCVBNM" myMode = "decrypt" # set to 'encrypt' or 'decrypt' From b01883e1508c77c69f8ebe5e6d095c71b4c56185 Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:22:42 +0530 Subject: [PATCH 08/13] update file --- ciphers/mono_alphabetic_ciphers.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index d6bc79995b4e..fd96d0cbf0ed 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -3,10 +3,7 @@ def translate_message(key, message, mode): """ - >>> translate_message( - "QWERTYUIOPASDFGHJKLZXCVBNM", - "Hello World!", - "encrypt") + >>> translate_message("QWERTYUIOPASDFGHJKLZXCVBNM","Hello World","encrypt") 'Pcssi Bidsm' """ charsA = LETTERS if mode == "decrypt" else key @@ -29,7 +26,7 @@ def translate_message(key, message, mode): def encrypt_message(key: str, message: str) -> str: """ - >>> encrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World!") + >>> encrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World") 'Pcssi Bidsm' """ return translate_message(key, message, "encrypt") @@ -37,14 +34,14 @@ def encrypt_message(key: str, message: str) -> str: def decrypt_message(key: str, message: str) -> str: """ - >>> decrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World!") + >>> decrypt_message("QWERTYUIOPASDFGHJKLZXCVBNM", "Hello World") 'Itssg Vgksr' """ return translate_message(key, message, "decrypt") def main(): - myMessage = "Hello World!" + myMessage = "Hello World" myKey = "QWERTYUIOPASDFGHJKLZXCVBNM" myMode = "decrypt" # set to 'encrypt' or 'decrypt' From e038ac4fda48d95cb400930281db560bb554aca6 Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 23:00:44 +0530 Subject: [PATCH 09/13] update file --- ciphers/mono_alphabetic_ciphers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index fd96d0cbf0ed..cb6c263c3cac 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -49,8 +49,8 @@ def main(): translated = encrypt_message(myKey, myMessage) elif myMode == "decrypt": translated = decrypt_message(myKey, myMessage) - print("Using key %s" % (myKey)) - print("The %sed message is:" % (myMode)) + print(f"Using key %s {myKey}") + print(f"The %sed message is {myMode}") print(translated) From 0aba1d07f1b83b8bdf207575938cc31f5f99d408 Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 23:04:11 +0530 Subject: [PATCH 10/13] update file --- ciphers/mono_alphabetic_ciphers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index cb6c263c3cac..a839eb13bfb0 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -50,8 +50,7 @@ def main(): elif myMode == "decrypt": translated = decrypt_message(myKey, myMessage) print(f"Using key %s {myKey}") - print(f"The %sed message is {myMode}") - print(translated) + print(f"The {myMode}ed message is: {translated}") if __name__ == "__main__": From 63a3e411e16aa2f4c502469fdb4d9557d307929a Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 23:07:42 +0530 Subject: [PATCH 11/13] update file --- ciphers/mono_alphabetic_ciphers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index a839eb13bfb0..fc762f63ca43 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -49,7 +49,7 @@ def main(): translated = encrypt_message(myKey, myMessage) elif myMode == "decrypt": translated = decrypt_message(myKey, myMessage) - print(f"Using key %s {myKey}") + print(f"Using key is {myKey}") print(f"The {myMode}ed message is: {translated}") From a95f5a4ad465d937ab65df7df0d4a6caf199f1e9 Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 23:16:07 +0530 Subject: [PATCH 12/13] update file --- ciphers/mono_alphabetic_ciphers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index fc762f63ca43..a10d9cf723ee 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -49,8 +49,7 @@ def main(): translated = encrypt_message(myKey, myMessage) elif myMode == "decrypt": translated = decrypt_message(myKey, myMessage) - print(f"Using key is {myKey}") - print(f"The {myMode}ed message is: {translated}") + print(f"Using the key {myKey}, the {myMode}ed message is: {translated}") if __name__ == "__main__": From ee5ce52ca580a818796ee6bd20489d0c7d741084 Mon Sep 17 00:00:00 2001 From: RadadiyaMohit <30775542+radadiyamohit81@users.noreply.github.com> Date: Sat, 17 Oct 2020 23:24:38 +0530 Subject: [PATCH 13/13] update file --- ciphers/mono_alphabetic_ciphers.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ciphers/mono_alphabetic_ciphers.py b/ciphers/mono_alphabetic_ciphers.py index a10d9cf723ee..0a29d6442896 100644 --- a/ciphers/mono_alphabetic_ciphers.py +++ b/ciphers/mono_alphabetic_ciphers.py @@ -6,18 +6,18 @@ def translate_message(key, message, mode): >>> translate_message("QWERTYUIOPASDFGHJKLZXCVBNM","Hello World","encrypt") 'Pcssi Bidsm' """ - charsA = LETTERS if mode == "decrypt" else key - charsB = key if mode == "decrypt" else LETTERS + chars_a = LETTERS if mode == "decrypt" else key + chars_b = key if mode == "decrypt" else LETTERS translated = "" # loop through each symbol in the message for symbol in message: - if symbol.upper() in charsA: + if symbol.upper() in chars_a: # encrypt/decrypt the symbol - symIndex = charsA.find(symbol.upper()) + sym_index = chars_a.find(symbol.upper()) if symbol.isupper(): - translated += charsB[symIndex].upper() + translated += chars_b[sym_index].upper() else: - translated += charsB[symIndex].lower() + translated += chars_b[sym_index].lower() else: # symbol is not in LETTERS, just add it translated += symbol @@ -41,15 +41,15 @@ def decrypt_message(key: str, message: str) -> str: def main(): - myMessage = "Hello World" - myKey = "QWERTYUIOPASDFGHJKLZXCVBNM" - myMode = "decrypt" # set to 'encrypt' or 'decrypt' - - if myMode == "encrypt": - translated = encrypt_message(myKey, myMessage) - elif myMode == "decrypt": - translated = decrypt_message(myKey, myMessage) - print(f"Using the key {myKey}, the {myMode}ed message is: {translated}") + message = "Hello World" + key = "QWERTYUIOPASDFGHJKLZXCVBNM" + mode = "decrypt" # set to 'encrypt' or 'decrypt' + + if mode == "encrypt": + translated = encrypt_message(key, message) + elif mode == "decrypt": + translated = decrypt_message(key, message) + print(f"Using the key {key}, the {mode}ed message is: {translated}") if __name__ == "__main__":