Make this code better

Code doesn't work for some reason [Python]

Basically, I wrote a program to shift letters down & up until they found a word in a message, and then move onto the next message, and ect. until they found all of them. Once they were finished finding all of them, all they had to do was print out ('{message} : {shifted}')

import random 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'] for n in range(0, len(alphabet)): alphabet[n] = alphabet[n].lower() file = open('../words.txt', 'r') words = file.readlines() file.close() for x in range(0, len(words)): if '\n' in words[x]: words[x] = words[x].replace('\n', '') encrypted = "jgnnq htkgpf og jqrg aqw fkg" encrypted = encrypted.lower() targets = encrypted.split() caesared = {} for target in range(0, len(targets)): shift = 0 while targets[target] not in words: new = '' for letter in targets[target]: if letter not in alphabet: new += letter else: scale = alphabet.index(letter)-shift while scale<0: scale += len(alphabet) new += alphabet[scale] targets[target] = new shift += 1 caesared[targets[target]] = shift-1 for caesar in caesared: if caesar not in words: pass else: print(caesar+":",caesared[caesar])

Reactions 1 reactions

otac_ Dont fuckin worry bout it commented on this code
if it helps, you can use this script to encrypt anything:
1) Change the "file" variable to your desired file
2) Write something in the file you've chosen
3) Run program

Comment on this code:

Please Login or Register to leave a comment.