Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed administrative_module/A.jpg
Binary file not shown.
Binary file added administrative_module/French_vigenere_test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added administrative_module/Spanish_ceasar_test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion administrative_module/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

Binary file added administrative_module/nyetest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added administrative_module/starwarstest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions decoder_module/ceasar_hacker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from decoder_module import detectEnglish


class CeasarHacker:

@staticmethod
def crack_ceasar(string):
# message = 'GUVF VF ZL FRPERG ZRFFNTR.'#This is here for testing purposes
LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZÜÑÍÓÉÁÚÇÈÏÛÔÎËÊÄÂ' # This is the alpahabet that will be used for the ceaser cipher
final_output = ''
final_output_fail = ''
fo = open(r"../files/dictionary.txt", encoding='utf8')
words = fo.readlines()
fo.close()
for key in range(len(LETTERS)):
translated = ''
for symbol in string:
if symbol in LETTERS:
num = LETTERS.find(symbol)
num = num - key
if num < 0:
num = num + len(LETTERS)
translated = translated + LETTERS[num]
else:
translated = translated + symbol
if detectEnglish.isEnglish(translated, wordPercentage=100):
if len(translated)==len(string):
final_output += translated + '\n'
if final_output != '':
return final_output
if final_output == '':
return "There was no crack found. Ensure that you are correctly copying your cipher."
#print(CeasarHacker.crack_ceasar('SUXHED')) #This is a testing output
50 changes: 50 additions & 0 deletions decoder_module/detectEnglish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
UPPERLETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZÜÑÍÓÉÁÚÇÈÏÛÔÎËÊÄÂ'
LETTERS_AND_SPACE = UPPERLETTERS + UPPERLETTERS.lower() + ' \t\n'


def loadDictionary():
os.chdir('../files')
dictionaryFile = open("../files/dictionary.txt", encoding="utf8")
englishWords = {}
for word in dictionaryFile.read().split('\n'):
englishWords[word] = None
dictionaryFile.close()
return englishWords


ENGLISH_WORDS = loadDictionary()


def getEnglishCount(message):
message = message.upper()
message = removeNonLetters(message)
possibleWords = message.split()

if possibleWords == []:
return 0.0 # no words at all, so return 0.0

matches = 0
for word in possibleWords:
if word in ENGLISH_WORDS:
matches += 1
return float(matches) / len(possibleWords)


def removeNonLetters(message):
lettersOnly = []
for symbol in message:
if symbol in LETTERS_AND_SPACE:
lettersOnly.append(symbol)
return ''.join(lettersOnly)


def isEnglish(message, wordPercentage=20, letterPercentage=85):
# By default, 20% of the words must exist in the dictionary file, and
# 85% of all the characters in the message must be letters or spaces
# (not punctuation or numbers).
wordsMatch = getEnglishCount(message) * 100 >= wordPercentage
numLetters = len(removeNonLetters(message))
messageLettersPercentage = float(numLetters) / len(message) * 100
lettersMatch = messageLettersPercentage >= letterPercentage
return wordsMatch and lettersMatch
45 changes: 45 additions & 0 deletions decoder_module/makeWordPatterns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pprint


def getWordPattern(word):
# Returns a string of the pattern form of the given word.
# e.g. '0.1.2.3.4.1.2.3.5.6' for 'DUSTBUSTER'
word = word.upper()
nextNum = 0
letterNums = {}
wordPattern = []

for letter in word:
if letter not in letterNums:
letterNums[letter] = str(nextNum)
nextNum += 1
wordPattern.append(letterNums[letter])
return '.'.join(wordPattern)


def main():
allPatterns = {}

fo = open(r"../files/dictionary.txt", encoding="utf8")
wordList = fo.read().split('\n')
fo.close()

for word in wordList:
# Get the pattern for each string in wordList.
pattern = getWordPattern(word)

if pattern not in allPatterns:
allPatterns[pattern] = [word]
else:
allPatterns[pattern].append(word)

# This is code that writes code. The wordPatterns.py file contains
# one very, very large assignment statement.
fo = open(r'C:\Users\grant\Documents\GitHub\Cerebro\decoder_module\wordPatterns.py', 'w',encoding='utf8')
fo.write('allPatterns = ')
fo.write(pprint.pformat(allPatterns))
fo.close()


if __name__ == '__main__':
main()
Loading