Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import enchant
- print("\n\n");
- en = enchant.Dict("en_US")
- def caesar_multiple(plain_text, rot):
- lower_text=plain_text.lower()
- en_text=""
- for char in lower_text:
- new_ascii_char = ord(char)-rot #subtracting the key from the ascii value #ord converts charachter to ascii value
- if char == " ":
- encrypt_char = " "
- elif new_ascii_char>=97:
- encrypt_char= chr(new_ascii_char)
- else:
- new_ascii_value= ord('z')-(ord('a')-new_ascii_char)+1
- encrypt_char = chr(new_ascii_value)
- en_text = en_text+encrypt_char # encrypted text
- return en_text
- for filenum in range(1,6):
- filename = str(filenum) + ".txt"
- file = open(filename) #open file
- text = file.read() #read file
- for rot in range(1,27):
- decryption_found = True
- decrypted = caesar_multiple(text, rot)
- for word in decrypted.split():
- is_english_word = en.check(word)
- if not is_english_word:
- decryption_found = False
- break
- if decryption_found:
- print("File: " + filename + " | Encrypted text: " + text + " | Decrypted text: " + decrypted + " | Key: " + str(rot))
- print("\n")
- break
Advertisement
Add Comment
Please, Sign In to add comment