Collection of python scripts to decrypt or encrypt stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cipher/caesar.py

38 lines
1.1 KiB

#!/usr/bin/env python
from lib.input import *
from lib.vars import alphabet
from lib.vars import listToString
if( inputHasKeys(["-k", "-i", "-a"]) ):
in_key = int(getValueOfKey("-k"))
in_txt = getValueOfKey("-i")
in_alphabet = getValueOfKey("-a")
else:
print("file.py -k {int KEY} -i {string TXT} -a {string ALPHABET_TYPE}")
print("-k: The encryption/decryption key")
print("-i: The text to be encrypted/decrypted")
print("-a: The alphabet (SWE or ENG)")
exit()
alen = len(alphabet[in_alphabet])
txt_list = list(in_txt)
decryp_list = [""] * len(in_txt)
charindex = -1
for char in txt_list: # loop through all of the chars
charindex = charindex + 1
index = alphabet[in_alphabet].index(char)
print("Decrypting char-index: " + str(charindex) + " (" + char + ":" + str(index) + ")")
index = index + in_key # shift the alphabet
while( index > alen - 1 ): #cycle through the alphabet
index = index - alen
print(" Alphabet cycle, index: " + str(index))
charDe = alphabet[in_alphabet][index]
decryp_list[charindex] = charDe
print( "Output: " + listToString(decryp_list) )