-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesar_cracker.py
More file actions
27 lines (24 loc) · 1.6 KB
/
caesar_cracker.py
File metadata and controls
27 lines (24 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Caesar Cipher Brute force function
# 3 November 2021
# Version 1.1
# NOTE: Capitals only, spaces not a part of the shift
# Wayne Caissie
def caesar_cipher():
"""This script will brute force a solution to a shift cipher."""
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # Creates legal letters
new_message = '' # Used in the code to create an output message
message = input('What\'s the message? > ') # Input message
key = 1
while key <= 26:
for i in message:
if i == " ": # If current letter is actually a space
new_message += i # Go ahead and add just the space to the message
elif letters.index(i) - key < 0: # The next few lines deal with wrapping around
letter_index = (letters.index(i) - key) + len(letters)
else:
letter_index = (letters.index(i) - key)
if i != " ": # When current letter in the message isn't a space
new_message += letters[letter_index] # Add the changed letter to the new message
print(new_message + " KEY: " + str(key)) # Display the message using the current 's' or key
key += 1
new_message = "" # Increments the key or 's' value and resets the message