Skip to content

Instantly share code, notes, and snippets.

@mmafrar
Created December 19, 2016 20:39
Show Gist options
  • Save mmafrar/8326a0e970a7f4a1c0a17795b8506c13 to your computer and use it in GitHub Desktop.
Save mmafrar/8326a0e970a7f4a1c0a17795b8506c13 to your computer and use it in GitHub Desktop.
A simple demontration on running a brute force attack on Caeser Cipher encoded text.
# Caesar Cipher
MAX_KEY_SIZE = 26
def getTranslatedMessage(mode, message, key):
if mode[0] == 'd':
key = -key
translated = ''
for symbol in message:
if symbol.isalpha():
num = ord(symbol)
num += key
if symbol.isupper():
if num > ord('Z'):
num -= 26
elif num < ord('A'):
num += 26
elif symbol.islower():
if num > ord('z'):
num -= 26
elif num < ord('a'):
num += 26
translated += chr(num)
else:
translated += symbol
return translated
print('Enter your input filename: ')
file_in = input()
fin = open(file_in, 'r')
for line in fin:
line = line.strip()
for i in range(MAX_KEY_SIZE + 1):
print(getTranslatedMessage('d', line, i))
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment