def decrypt(filename, key, alphabets) : contents = get_contents(filename) # split contents by newline characters? lines = get_lines(contents) output = "" for line in lines : count = 0 for char in line : if (Letter.isLetter(char)): current_alphabet = alphabets[count] repeat_value = find_in_alphabet(char, current_alphabet) char_value = 65 + repeat_value output = output + chr(char_value) count = count + 1 if count > len(alphabets) -1: count = 0 else: output = output + char output = output + "\n" return output
def caesar(contents, mod) : output = "" for char in contents: if (Letter.isLetter(char)): curr = Letter(char) cyphered = caesar_cypher(curr, mod) output = output + cyphered else: output = output + char return output
def atbash(contents) : output = "" for char in contents: if (Letter.isLetter(char)): curr = Letter(char) cyphered = atbash_cypher(curr) output = output + cyphered else: output = output + char return output
def encrypt(filename, key, alphabets) : contents = get_contents(filename) lines = get_lines(contents) repeating = [] for line in lines : index = 0 repeat_line = "" for i in range(len(line)) : char = contents[i] if (Letter.isLetter(char)) : repeat_line = repeat_line + key[index % len(key)] index = index + 1 else : repeat_line = repeat_line + char repeating.append(repeat_line) output = "" for line in lines : count = 0 for i in range(len(line)) : target_char = line[i] if (Letter.isLetter(target_char)) : current_alphabet = alphabets[count] index = find_in_alphabet(target_char, default) out = current_alphabet[index] output = output + out count = count + 1 if count > len(alphabets)-1 : count = 0 else : output = output + target_char output = output + "\n" return output
def main() : file = open("Atbash.txt", "r") contents = file.read() contents = contents.upper() output = "" for char in contents: if (Letter.isLetter(char)): curr = Letter(char) cyphered = atbash_cypher(curr) output = output + cyphered else: output = output + char print(output) file.close() file = open("output.txt", "w") file.write(output) file.close()
def main() : file = open("Caesar.txt", "r") mod = -3 contents = file.read() contents = contents.upper() output = "" for char in contents: if (Letter.isLetter(char)): curr = Letter(char) cyphered = caesar_cypher(curr, mod) output = output + cyphered else: output = output + char print(output) file.close() file = open("output.txt", "w") file.write(output)