Added Caesar cipher decryptor

master
E. Almqvist 5 years ago
parent 4254b2f93b
commit 832f49c37d
  1. 27
      caesar.py
  2. BIN
      lib/__pycache__/vars.cpython-38.pyc
  3. 14
      lib/vars.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)

@ -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

Loading…
Cancel
Save