From 832f49c37d1b02da6415fe8cbb2ed2b6222ccd4f Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 7 May 2020 14:42:48 +0200 Subject: [PATCH] Added Caesar cipher decryptor --- caesar.py | 27 +++++++++++++++++++++++++++ lib/__pycache__/vars.cpython-38.pyc | Bin 0 -> 427 bytes lib/vars.py | 14 ++++++++------ 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 lib/__pycache__/vars.cpython-38.pyc diff --git a/caesar.py b/caesar.py index e69de29..9b1e6d4 100644 --- a/caesar.py +++ b/caesar.py @@ -0,0 +1,27 @@ +import sys +from lib.vars import alphabet + +if( len(sys.argv) >= 4 ): + in_key = int(sys.argv[1]) + in_txt = sys.argv[2] + in_alphabet = sys.argv[3] +else: + print("file.py {int KEY} {string TXT} {string ALPHABET_TYPE}") + exit() + +alen = len(alphabet[in_alphabet]) + +txt_list = list(in_txt) +decryp_list = [""] * len(in_txt) + +for char in txt_list: + index = alphabet[in_alphabet].index(char) + + index = index + in_key # shift the alphabet + while( index >= alen ): #cycle through the alphabet + diff = (index + in_key) - (alen - 1) + index = 0 + diff # a bit spaghetti but who doesn't like spaghetti + + decryp_list[txt_list.index(char)] = alphabet[in_alphabet][index] + +print(decryp_list) diff --git a/lib/__pycache__/vars.cpython-38.pyc b/lib/__pycache__/vars.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e012f29d74808bb16689acef9992546d22b04501 GIT binary patch literal 427 zcmbV}%}T>i5QXm~vBui^|68r?O6bOHU6kUcxGO>tAqyqVxhAP;6O**HZhZkCLIu}? zFW_6u)>qJtE3X#CwFl-LK86_>=D1kQ3nl&S>GXkwc>RLEDl0fpmEJ0Y06~Ke15?Oh z8YX6t$1DmcVh;0Iz#^8gj1{b64eQvzrdP86HHQ+muZBc>~+G1K+C zrjC5MpTylHo^8F^I<)onNwZZm?1JojXHFRVPDf^TAsxwIVgrGjvH8<|6iHR>`?il= z%a3}}lA#k?M@iI`ZkAeZ5c@K*!k}Xfoh03h$86Sn5eA`bsAq`ORJN}*jGSiDCzM!s A!vFvP literal 0 HcmV?d00001 diff --git a/lib/vars.py b/lib/vars.py index f7bdd2e..995c07c 100644 --- a/lib/vars.py +++ b/lib/vars.py @@ -1,10 +1,12 @@ -alphabet = ["a", "b" ] -F G H I J +eng_alphabet = ["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"] -K L M N O +swe_alphabet = ["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", "å", "ä", "ö"] -P Q R S T -U V W X Y +# Definitions +alphabet = dict() -Z Å Ä Ö +alphabet["ENG"] = eng_alphabet +alphabet["SWE"] = swe_alphabet + +# Functions