Fixed some Pytest stuff

This commit is contained in:
Brandon 2020-04-29 00:41:48 +01:00
parent 0ff379b475
commit 6009f35c14
29 changed files with 253 additions and 123 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

14
.idea/Ciphey.iml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/env" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (Ciphey)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Ciphey.iml" filepath="$PROJECT_DIR$/.idea/Ciphey.iml" />
</modules>
</component>
</project>

6
.idea/other.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PySciProjectComponent">
<option name="PY_SCI_VIEW_SUGGESTED" value="true" />
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

2
MANIFEST.in Normal file
View File

@ -0,0 +1,2 @@
include /appp/languageCheckerMod/*
include README.MD

View File

@ -1,3 +1,7 @@
![Ciphey][logo.png]
<img src="https://img.shields.io/badge/made%20with-python-blue.svg" alt="made with python">
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![Ciphey's Tests](https://github.com/brandonskerritt/Ciphey/workflows/Python%20application/badge.svg?branch=master)
# What is this? # What is this?
Ciphey is an automated decryption tool. Ciphey is an automated decryption tool.
You put in encrypted text, and it outputs the decrypted text. You put in encrypted text, and it outputs the decrypted text.

View File

View File

@ -1,8 +1,8 @@
from Decryptor.Encoding.base64 import Base64 from app.Decryptor.Encoding.base64 import Base64
from Decryptor.Encoding.binary import Binary from app.Decryptor.Encoding.binary import Binary
from Decryptor.Encoding.hexadecimal import Hexadecimal from app.Decryptor.Encoding.hexadecimal import Hexadecimal
from Decryptor.Encoding.ascii import Ascii from app.Decryptor.Encoding.ascii import Ascii
from Decryptor.Encoding.morsecode import MorseCode from app.Decryptor.Encoding.morsecode import MorseCode
class EncodingParent: class EncodingParent:
def __init__(self, lc): def __init__(self, lc):

View File

View File

@ -1,8 +1,8 @@
from Decryptor.basicEncryption.caesar import Caesar import app.Decryptor.basicEncryption.caesar
from Decryptor.basicEncryption.reverse import Reverse import app.Decryptor.basicEncryption.reverse
from Decryptor.basicEncryption.viginere import Viginere import app.Decryptor.basicEncryption.viginere
from Decryptor.basicEncryption.pigLatin import PigLatin import app.Decryptor.basicEncryption.pigLatin
from Decryptor.basicEncryption.transposition import Transposition
""" """
So I want to assign the prob distribution to objects So I want to assign the prob distribution to objects
so it makes sense to do this? so it makes sense to do this?
@ -32,23 +32,22 @@ for key, val in self.prob:
list_objs.insert(counter, list_objs.pop(listCounter)) list_objs.insert(counter, list_objs.pop(listCounter))
counter = counter + 1 counter = counter + 1
Eventually we get a sorted list of objs Eventually we get a sorted list of obj
""" """
class BasicParent: class BasicParent:
def __init__(self, lc): def __init__(self, lc):
self.lc = lc self.lc = lc
self.caesar = Caesar(self.lc) self.caesar = app.Decryptor.basicEncryption.caesar.Caesar(self.lc)
self.reverse = Reverse(self.lc) self.reverse = app.Decryptor.basicEncryption.reverse.Reverse(self.lc)
self.viginere = Viginere(self.lc) self.viginere = app.Decryptor.basicEncryption.viginere.Viginere(self.lc)
self.pig = PigLatin(self.lc) self.pig = app.Decryptor.basicEncryption.pigLatin.PigLatin(self.lc)
# self.trans = Transposition(self.lc) # self.trans = Transposition(self.lc)
self.list_of_objects = [self.caesar, self.reverse, self.pig] self.list_of_objects = [self.caesar, self.reverse, self.pig]
def decrypt(self, text): def decrypt(self, text):
self.text = text self.text = text
from multiprocessing.dummy import Pool as ThreadPool from multiprocessing.dummy import Pool as ThreadPool
pool = ThreadPool(4) pool = ThreadPool(4)
answers = pool.map(self.callDecrypt, self.list_of_objects) answers = pool.map(self.callDecrypt, self.list_of_objects)
@ -69,11 +68,13 @@ class BasicParent:
if result["IsPlaintext?"]: if result["IsPlaintext?"]:
return result return result
return {"lc": self.lc, "IsPlaintext?": False, "Plaintext": None, "Cipher": None, "Extra Information": None} return {"lc": self.lc, "IsPlaintext?": False, "Plaintext": None, "Cipher": None, "Extra Information": None}
def callDecrypt(self, obj): def callDecrypt(self, obj):
# i only exist to call decrypt # i only exist to call decrypt
return obj.decrypt(self.text) return obj.decrypt(self.text)
def setProbTable(self, prob): def setProbTable(self, prob):
"""I'm still writing this"""
self.probabilityDistribution = prob self.probabilityDistribution = prob
# we get a sorted list of objects :) # we get a sorted list of objects :)
counter = 0 counter = 0

View File

@ -8,16 +8,15 @@
Github: brandonskerritt Github: brandonskerritt
""" """
class Caesar(): class Caesar:
def __init__(self, lc): def __init__(self, lc):
self.lc = lc self.lc = lc
def getName(self): def getName(self):
return "Caesar" return "Caesar"
def decrypt(self, message): def decrypt(self, message):
''' Simple python program to bruteforce a caesar cipher''' """ Simple python program to bruteforce a caesar cipher"""
''' Simple python program for the caesar cipher'''
# Example string # Example string
message = message.lower() message = message.lower()
@ -49,5 +48,3 @@ class Caesar():
return {"lc": self.lc, "IsPlaintext?": True, "Plaintext": translated, "Cipher": "Caesar", "Extra Information": f"The rotation used is {counter}"} return {"lc": self.lc, "IsPlaintext?": True, "Plaintext": translated, "Cipher": "Caesar", "Extra Information": f"The rotation used is {counter}"}
# if none of them match English, return false! # if none of them match English, return false!
return {"lc": self.lc, "IsPlaintext?": False, "Plaintext": None, "Cipher": "Caesar", "Extra Information": None} return {"lc": self.lc, "IsPlaintext?": False, "Plaintext": None, "Cipher": "Caesar", "Extra Information": None}

View File

@ -1,8 +1,11 @@
import mathsHelper import app.mathsHelper
class Reverse: class Reverse:
def __init__(self, lc): def __init__(self, lc):
self.lc = lc self.lc = lc
self.mh = mathsHelper.mathsHelper() self.mh = app.mathsHelper.mathsHelper()
def decrypt(self, message): def decrypt(self, message):
message = self.mh.stripPuncuation(message) message = self.mh.stripPuncuation(message)
@ -12,5 +15,6 @@ class Reverse:
return {"lc": self.lc, "IsPlaintext?": True, "Plaintext": message, "Cipher": "Reverse", "Extra Information": None} return {"lc": self.lc, "IsPlaintext?": True, "Plaintext": message, "Cipher": "Reverse", "Extra Information": None}
else: else:
return {"lc": self.lc, "IsPlaintext?": False, "Plaintext": None, "Cipher": "Reverse", "Extra Information": None} return {"lc": self.lc, "IsPlaintext?": False, "Plaintext": None, "Cipher": "Reverse", "Extra Information": None}
def getName(self): def getName(self):
return "Reverse" return "Reverse"

View File

@ -1,5 +1,5 @@
import itertools, re import itertools, re
from Decryptor.basicEncryption import freqAnalysis import app.Decryptor.basicEncryption.freqAnalysis
class Viginere: class Viginere:
def __init__(self, lc): def __init__(self, lc):
self.LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' self.LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@ -173,7 +173,7 @@ class Viginere:
freqScores = [] freqScores = []
for possibleKey in self.LETTERS: for possibleKey in self.LETTERS:
decryptedText = self.decryptMessage(possibleKey, nthLetters) decryptedText = self.decryptMessage(possibleKey, nthLetters)
keyAndFreqMatchTuple = (possibleKey, freqAnalysis.englishFreqMatchScore(decryptedText)) keyAndFreqMatchTuple = (possibleKey, app.Decryptor.basicEncryption.freqAnalysis.englishFreqMatchScore(decryptedText))
freqScores.append(keyAndFreqMatchTuple) freqScores.append(keyAndFreqMatchTuple)
# Sort by match score: # Sort by match score:
freqScores.sort(key=self.getItemAtIndexOne, reverse=True) freqScores.sort(key=self.getItemAtIndexOne, reverse=True)

View File

@ -1,8 +1,13 @@
import sys import sys
sys.path.append("..") # sys.path.append('..')
import unittest import unittest
from app.Decryptor.Encoding.encodingParent import EncodingParent # from app.Decryptor.Encoding.encodingParent import EncodingParent
from languageCheckerMod.languageChecker import LanguageChecker import app.Decryptor.Encoding.encodingParent
import app.languageCheckerMod.LanguageChecker
import app.languageCheckerMod.LanguageChecker
#from languageCheckerMod import LanguageChecker
# python3 -m unittest Tests.testchi_squared # python3 -m unittest Tests.testchi_squared
# python -m unittest discover -s tests # python -m unittest discover -s tests
# python3 -m unittest discover -s Tests -p test*.py # python3 -m unittest discover -s Tests -p test*.py
@ -10,41 +15,41 @@ from languageCheckerMod.languageChecker import LanguageChecker
class TestNN(unittest.TestCase): class TestNN(unittest.TestCase):
def test_english_yes(self): def test_english_yes(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
ep = EncodingParent(lc) ep = app.Decryptor.Encoding.encodingParent.EncodingParent(lc)
result = ep.decrypt("eW91ciB0ZXh0") result = ep.decrypt("eW91ciB0ZXh0")
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_base64_spaces_yes(self): def test_base64_spaces_yes(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
ep = EncodingParent(lc) ep = app.Decryptor.Encoding.encodingParent.EncodingParent(lc)
result = ep.decrypt("SGVsbG8gSSBsaWtlIGRvZ3MgYW5kIGNhdHM=") result = ep.decrypt("SGVsbG8gSSBsaWtlIGRvZ3MgYW5kIGNhdHM=")
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_binary_spaces_yes(self): def test_binary_spaces_yes(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
ep = EncodingParent(lc) ep = app.Decryptor.Encoding.encodingParent.EncodingParent(lc)
result = ep.decrypt("01001000 01100101 01101100 01101100 01101111 00100000 01001001 00100000 01101100 01101001 01101011 01100101 00100000 01100100 01101111 01100111 01110011 00100000 01100001 01101110 01100100 00100000 01100011 01100001 01110100 01110011") result = ep.decrypt("01001000 01100101 01101100 01101100 01101111 00100000 01001001 00100000 01101100 01101001 01101011 01100101 00100000 01100100 01101111 01100111 01110011 00100000 01100001 01101110 01100100 00100000 01100011 01100001 01110100 01110011")
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_hex_spaces_yes(self): def test_hex_spaces_yes(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
ep = EncodingParent(lc) ep = app.Decryptor.Encoding.encodingParent.EncodingParent(lc)
result = ep.decrypt("68 65 6c 6c 6f 20 6f 6c 69 76 69 61 20 69 20 72 65 61 6c 6c 79 20 6c 69 6b 65 20 79 6f 75 72 20 64 6f 67") result = ep.decrypt("68 65 6c 6c 6f 20 6f 6c 69 76 69 61 20 69 20 72 65 61 6c 6c 79 20 6c 69 6b 65 20 79 6f 75 72 20 64 6f 67")
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_hex_spaces_yes(self): def test_hex_spaces_yes(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
ep = EncodingParent(lc) ep = app.Decryptor.Encoding.encodingParent.EncodingParent(lc)
a = "68656c6c6f206f 6c 69 76 69 61 20 69 20 72 65 61 6c 6c 79 20 6c 69 6b 65 20 79 6f 75 72 20 64 6f 67" a = "68656c6c6f206f 6c 69 76 69 61 20 69 20 72 65 61 6c 6c 79 20 6c 69 6b 65 20 79 6f 75 72 20 64 6f 67"
a = a.replace(" ", "") a = a.replace(" ", "")
result = ep.decrypt(a) result = ep.decrypt(a)
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_ascii(self): def test_ascii(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
ep = EncodingParent(lc) ep = app.Decryptor.Encoding.encodingParent.EncodingParent(lc)
a = "68 65 6C 6C 6F 20 64 6F 67" a = "68 65 6C 6C 6F 20 64 6F 67"
result = ep.decrypt(a) result = ep.decrypt(a)
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_morse(self): def test_morse(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
ep = EncodingParent(lc) ep = app.Decryptor.Encoding.encodingParent.EncodingParent(lc)
a = ".... . .-.. .-.. --- / -- -.-- / -. .- -- . / .. ... / -... .-. .- -. -.. --- -." a = ".... . .-.. .-.. --- / -- -.-- / -. .- -- . / .. ... / -... .-. .- -. -.. --- -."
result = ep.decrypt(a) result = ep.decrypt(a)
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)

View File

@ -1,30 +1,30 @@
import sys
sys.path.append("..")
import unittest import unittest
from Decryptor.basicEncryption.basic_parent import BasicParent import sys
from languageCheckerMod.languageChecker import LanguageChecker # sys.path.append("..")
import app.Decryptor.basicEncryption.basic_parent
import app.languageCheckerMod.LanguageChecker
# python3 -m unittest Tests.testchi_squared # python3 -m unittest Tests.testchi_squared
# python -m unittest discover -s tests # python -m unittest discover -s tests
# python3 -m unittest discover -s Tests -p test*.py # python3 -m unittest discover -s Tests -p test*.py
class TestBasicParent(unittest.TestCase): class TestBasicParent(unittest.TestCase):
def test_basic_parent_caesar_yes(self): def test_basic_parent_caesar_yes(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.languageCheckerMod.LanguageChecker.LanguageChecker()
bp = BasicParent(lc) bp = app.Decryptor.basicEncryption.basic_parent.BasicParent(lc)
result = bp.decrypt("uryyb zl sngure uryyb zl zbgure naq v ernyyl qb yvxr n tbbq ratyvfu oernxsnfg") result = bp.decrypt("uryyb zl sngure uryyb zl zbgure naq v ernyyl qb yvxr n tbbq ratyvfu oernxsnfg")
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_basic_parent_reverse_yes(self): def test_basic_parent_reverse_yes(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
bp = BasicParent(lc) bp = app.Decryptor.basicEncryption.basic_parent.BasicParent(lc)
result = bp.decrypt("tsafkaerb hsilgne doog a ekil od yllaer i dna rehtom ym olleh rehtaf ym olleh") result = bp.decrypt("tsafkaerb hsilgne doog a ekil od yllaer i dna rehtom ym olleh rehtaf ym olleh")
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_basic_parent_reverse_yes_2(self): def test_basic_parent_reverse_yes_2(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
bp = BasicParent(lc) bp = app.Decryptor.basicEncryption.basic_parent.BasicParent(lc)
result = bp.decrypt("sevom ylpmis rac eht ciffart ruoy lla gnillenut si hcihw redivorp NPV a ekilnU") result = bp.decrypt("sevom ylpmis rac eht ciffart ruoy lla gnillenut si hcihw redivorp NPV a ekilnU")
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_viginere_yes(self): def test_viginere_yes(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
bp = BasicParent(lc) bp = app.Decryptor.basicEncryption.basic_parent.BasicParent(lc)
result = bp.decrypt("""Adiz Avtzqeci Tmzubb wsa m Pmilqev halpqavtakuoi, lgouqdaf, kdmktsvmztsl, izr xoexghzr kkusitaaf. Vz wsa twbhdg ubalmmzhdad qz hce vmhsgohuqbo ox kaakulmd gxiwvos, krgdurdny i rcmmstugvtawz ca tzm ocicwxfg jf "stscmilpy" oid "uwydptsbuci" wabt hce Lcdwig eiovdnw. Bgfdny qe kddwtk qjnkqpsmev ba pz tzm roohwz at xoexghzr kkusicw izr vrlqrwxist uboedtuuznum. Pimifo Icmlv Emf DI, Lcdwig owdyzd xwd hce Ywhsmnemzh Xovm mby Cqxtsm Supacg (GUKE) oo Bdmfqclwg Bomk, Tzuhvif'a ocyetzqofifo ositjm. Rcm a lqys ce oie vzav wr Vpt 8, lpq gzclqab mekxabnittq tjr Ymdavn fihog cjgbhvnstkgds. Zm psqikmp o iuejqf jf lmoviiicqg aoj jdsvkavs Uzreiz qdpzmdg, dnutgrdny bts helpar jf lpq pjmtm, mb zlwkffjmwktoiiuix avczqzs ohsb ocplv nuby swbfwigk naf ohw Mzwbms umqcifm. Mtoej bts raj pq kjrcmp oo tzm Zooigvmz Khqauqvl Dincmalwdm, rhwzq vz cjmmhzd gvq ca tzm rwmsl lqgdgfa rcm a kbafzd-hzaumae kaakulmd, hce SKQ. Wi 1948 Tmzubb jgqzsy Msf Zsrmsv'e Qjmhcfwig Dincmalwdm vt Eizqcekbqf Pnadqfnilg, ivzrw pq onsaafsy if bts yenmxckmwvf ca tzm Yoiczmehzr uwydptwze oid tmoohe avfsmekbqr dn eifvzmsbuqvl tqazjgq. Pq kmolm m dvpwz ab ohw ktshiuix pvsaa at hojxtcbefmewn, afl bfzdakfsy okkuzgalqzu xhwuuqvl jmmqoigve gpcz ie hce Tmxcpsgd-Lvvbgbubnkq zqoxtawz, kciup isme xqdgo otaqfqev qz hce 1960k. Bgfdny'a tchokmjivlabk fzsmtfsy if i ofdmavmz krgaqqptawz wi 1952, wzmz vjmgaqlpad iohn wwzq goidt uzgeyix wi tzm Gbdtwl Wwigvwy. Vz aukqdoev bdsvtemzh rilp rshadm tcmmgvqg (xhwuuqvl uiehmalqab) vs sv mzoejvmhdvw ba dmikwz. Hpravs rdev qz 1954, xpsl whsm tow iszkk jqtjrw pug 42id tqdhcdsg, rfjm ugmbddw xawnofqzu. Vn avcizsl lqhzreqzsy tzif vds vmmhc wsa eidcalq; vds ewfvzr svp gjmw wfvzrk jqzdenmp vds vmmhc wsa mqxivmzhvl. Gv 10 Esktwunsm 2009, fgtxcrifo mb Dnlmdbzt uiydviyv, Nfdtaat Dmiem Ywiikbqf Bojlab Wrgez avdw iz cafakuog pmjxwx ahwxcby gv nscadn at ohw Jdwoikp scqejvysit xwd "hce sxboglavs kvy zm ion tjmmhzd." Sa at Haq 2012 i bfdvsbq azmtmd'g widt ion bwnafz tzm Tcpsw wr Zjrva ivdcz eaigd yzmbo Tmzubb a kbmhptgzk dvrvwz wa efiohzd.""") result = bp.decrypt("""Adiz Avtzqeci Tmzubb wsa m Pmilqev halpqavtakuoi, lgouqdaf, kdmktsvmztsl, izr xoexghzr kkusitaaf. Vz wsa twbhdg ubalmmzhdad qz hce vmhsgohuqbo ox kaakulmd gxiwvos, krgdurdny i rcmmstugvtawz ca tzm ocicwxfg jf "stscmilpy" oid "uwydptsbuci" wabt hce Lcdwig eiovdnw. Bgfdny qe kddwtk qjnkqpsmev ba pz tzm roohwz at xoexghzr kkusicw izr vrlqrwxist uboedtuuznum. Pimifo Icmlv Emf DI, Lcdwig owdyzd xwd hce Ywhsmnemzh Xovm mby Cqxtsm Supacg (GUKE) oo Bdmfqclwg Bomk, Tzuhvif'a ocyetzqofifo ositjm. Rcm a lqys ce oie vzav wr Vpt 8, lpq gzclqab mekxabnittq tjr Ymdavn fihog cjgbhvnstkgds. Zm psqikmp o iuejqf jf lmoviiicqg aoj jdsvkavs Uzreiz qdpzmdg, dnutgrdny bts helpar jf lpq pjmtm, mb zlwkffjmwktoiiuix avczqzs ohsb ocplv nuby swbfwigk naf ohw Mzwbms umqcifm. Mtoej bts raj pq kjrcmp oo tzm Zooigvmz Khqauqvl Dincmalwdm, rhwzq vz cjmmhzd gvq ca tzm rwmsl lqgdgfa rcm a kbafzd-hzaumae kaakulmd, hce SKQ. Wi 1948 Tmzubb jgqzsy Msf Zsrmsv'e Qjmhcfwig Dincmalwdm vt Eizqcekbqf Pnadqfnilg, ivzrw pq onsaafsy if bts yenmxckmwvf ca tzm Yoiczmehzr uwydptwze oid tmoohe avfsmekbqr dn eifvzmsbuqvl tqazjgq. Pq kmolm m dvpwz ab ohw ktshiuix pvsaa at hojxtcbefmewn, afl bfzdakfsy okkuzgalqzu xhwuuqvl jmmqoigve gpcz ie hce Tmxcpsgd-Lvvbgbubnkq zqoxtawz, kciup isme xqdgo otaqfqev qz hce 1960k. Bgfdny'a tchokmjivlabk fzsmtfsy if i ofdmavmz krgaqqptawz wi 1952, wzmz vjmgaqlpad iohn wwzq goidt uzgeyix wi tzm Gbdtwl Wwigvwy. Vz aukqdoev bdsvtemzh rilp rshadm tcmmgvqg (xhwuuqvl uiehmalqab) vs sv mzoejvmhdvw ba dmikwz. Hpravs rdev qz 1954, xpsl whsm tow iszkk jqtjrw pug 42id tqdhcdsg, rfjm ugmbddw xawnofqzu. Vn avcizsl lqhzreqzsy tzif vds vmmhc wsa eidcalq; vds ewfvzr svp gjmw wfvzrk jqzdenmp vds vmmhc wsa mqxivmzhvl. Gv 10 Esktwunsm 2009, fgtxcrifo mb Dnlmdbzt uiydviyv, Nfdtaat Dmiem Ywiikbqf Bojlab Wrgez avdw iz cafakuog pmjxwx ahwxcby gv nscadn at ohw Jdwoikp scqejvysit xwd "hce sxboglavs kvy zm ion tjmmhzd." Sa at Haq 2012 i bfdvsbq azmtmd'g widt ion bwnafz tzm Tcpsw wr Zjrva ivdcz eaigd yzmbo Tmzubb a kbmhptgzk dvrvwz wa efiohzd.""")
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)

View File

@ -1,50 +1,58 @@
import sys import sys
sys.path.append("..") # sys.path.append("..")
import unittest import unittest
from app.Decryptor.basicEncryption.caesar import Caesar from app.Decryptor.basicEncryption.caesar import Caesar
from languageCheckerMod.languageChecker import LanguageChecker import app.languageCheckerMod.LanguageChecker
# python3 -m unittest Tests.testchi_squared # python3 -m unittest Tests.testchi_squared
# python -m unittest discover -s tests # python -m unittest discover -s tests
# python3 -m unittest discover -s Tests -p test*.py # python3 -m unittest discover -s Tests -p test*.py
# {"lc": self.lc, "IsPlaintext?": True, "Plaintext": translated, "Cipher": "Caesar"} # {"lc": self.lc, "IsPlaintext?": True, "Plaintext": translated, "Cipher": "Caesar"}
class TestChi(unittest.TestCase): class TestChi(unittest.TestCase):
def test_caesar_yes(self): def test_caesar_yes(self):
"""Checks to see if it returns True (it should)""" """Checks to see if it returns True (it should)"""
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
c = Caesar(lc) c = Caesar.Caesar(lc)
result = c.decrypt("uryyb zl sngure uryyb zl zbgure naq v ernyyl qb yvxr n tbbq ratyvfu oernxsnfg") result = c.decrypt("uryyb zl sngure uryyb zl zbgure naq v ernyyl qb yvxr n tbbq ratyvfu oernxsnfg")
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_caesar_no(self): def test_caesar_no(self):
"""Checks to see if it returns True (it should)""" """Checks to see if it returns True (it should)"""
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
c = Caesar(lc) c = Caesar.Caesar(lc)
result = c.decrypt("o iozad iikwas") result = c.decrypt("o iozad iikwas")
self.assertEqual(result['IsPlaintext?'], False) self.assertEqual(result['IsPlaintext?'], False)
def test_caesar_plaintext_yes(self): def test_caesar_plaintext_yes(self):
"""Checks to see if it returns True (it should) """Checks to see if it returns True (it should)
Ok so this returns false becaues caesar only does up to 25, not 26 Ok so this returns false becaues caesar only does up to 25, not 26
so plaintext returns false!""" so plaintext returns false!"""
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
c = Caesar(lc) c = Caesar.Caesar(lc)
result = c.decrypt("What about plaintext?") result = c.decrypt("What about plaintext?")
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_caesar_english_comparison(self): def test_caesar_english_comparison(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
c = Caesar(lc) c = Caesar.Caesar(lc)
result = c.decrypt("Pm ol ohk hufaopun jvumpkluaphs av zhf, ol dyval pa pu jpwoly, aoha pz, if zv johunpun aol vykly vm aol slaalyz vm aol hswohila, aoha uva h dvyk jvbsk il thkl vba.") result = c.decrypt("Pm ol ohk hufaopun jvumpkluaphs av zhf, ol dyval pa pu jpwoly, aoha pz, if zv johunpun aol vykly vm aol slaalyz vm aol hswohila, aoha uva h dvyk jvbsk il thkl vba.")
self.assertEqual(result['IsPlaintext?'], True) self.assertEqual(result['IsPlaintext?'], True)
def test_caesar_english_comparison_yeet(self): def test_caesar_english_comparison_yeet(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
c = Caesar(lc) c = Caesar.Caesar(lc)
result = c.decrypt("Onrs hr mnv knbjdc enq fnnc. Sgzmj xnt zkk enq ozqshbhozshmf, zmc okdzrd bnmshmtd sn unsd enq sgd itcfdldms xnt zfqdd vhsg. Zr nsgdq trdqr gzud onhmsdc nts, sgdqd hr zcchshnmzk hmenqlzshnm sgzs NO gzr kdes nts ne sgdhq nqhfhmzk onrs sgzs sgdx gzud zccdc hm sgdhq bnlldmsr, rn okdzrd qdzc etqsgdq sn fds sgd etkk rbnod ne sgd rhstzshnm.") result = c.decrypt("Onrs hr mnv knbjdc enq fnnc. Sgzmj xnt zkk enq ozqshbhozshmf, zmc okdzrd bnmshmtd sn unsd enq sgd itcfdldms xnt zfqdd vhsg. Zr nsgdq trdqr gzud onhmsdc nts, sgdqd hr zcchshnmzk hmenqlzshnm sgzs NO gzr kdes nts ne sgdhq nqhfhmzk onrs sgzs sgdx gzud zccdc hm sgdhq bnlldmsr, rn okdzrd qdzc etqsgdq sn fds sgd etkk rbnod ne sgd rhstzshnm.")
self.assertEqual(result['Plaintext'], "Post is now locked for good. Thank you all for participating, and please continue to vote for the judgement you agree with. As other users have pointed out, there is additional information that OP has left out of their original post that they have added in their comments, so please read further to get the full scope of the situation.".lower()) self.assertEqual(result['Plaintext'], "Post is now locked for good. Thank you all for participating, and please continue to vote for the judgement you agree with. As other users have pointed out, there is additional information that OP has left out of their original post that they have added in their comments, so please read further to get the full scope of the situation.".lower())
def test_caesar_what_is_this(self): def test_caesar_what_is_this(self):
"""Checks to see if it returns True (it should) """Checks to see if it returns True (it should)
Ok so this returns false becaues caesar only does up to 25, not 26 Ok so this returns false becaues caesar only does up to 25, not 26
so plaintext returns false!""" so plaintext returns false!"""
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
c = Caesar(lc) c = Caesar.Caesar(lc)
result = c.decrypt("?") result = c.decrypt("?")
self.assertEqual(result['IsPlaintext?'], False) self.assertEqual(result['IsPlaintext?'], False)

View File

@ -1,7 +1,7 @@
import unittest
import sys import sys
sys.path.append("..") sys.path.append("..")
import unittest import app.languageCheckerMod.chisquared
from app.languageCheckerMod import chisquared
# python3 -m unittest Tests.testchi_squared # python3 -m unittest Tests.testchi_squared
# python -m unittest discover -s tests # python -m unittest discover -s tests
# python3 -m unittest discover -s Tests -p test*.py # python3 -m unittest discover -s Tests -p test*.py
@ -9,28 +9,28 @@ from app.languageCheckerMod import chisquared
class TestChi(unittest.TestCase): class TestChi(unittest.TestCase):
def test_chi_english_yes(self): def test_chi_english_yes(self):
"""Checks to see if it returns True (it should)""" """Checks to see if it returns True (it should)"""
self.chi = chisquared.chiSquared() self.chi = app.languageCheckerMod.chisquared.chiSquared()
""" """
Tests to see whether a sentene is classified as English or not Tests to see whether a sentene is classified as English or not
""" """
result = self.chi.checkChi("Hello my name is Brandon and I'm a top secret message") result = self.chi.checkChi("Hello my name is Brandon and I'm a top secret message")
self.assertEqual(result, True) self.assertEqual(result, True)
def test_chi_english_caps(self): def test_chi_english_caps(self):
self.chi = chisquared.chiSquared() self.chi = app.languageCheckerMod.chisquared.chiSquared()
""" """
Tests to see whether a sentene is classified as English or not Tests to see whether a sentene is classified as English or not
""" """
result = self.chi.checkChi("Hello My NaME IS BraNdOnnn And I LOVE You!") result = self.chi.checkChi("Hello My NaME IS BraNdOnnn And I LOVE You!")
self.assertEqual(result, True) self.assertEqual(result, True)
def tests_english_no_words(self): def tests_english_no_words(self):
self.chi = chisquared.chiSquared() self.chi = app.languageCheckerMod.chisquared.chiSquared()
""" """
Tests to see whether a sentene is classified as English or not Tests to see whether a sentene is classified as English or not
""" """
result = self.chi.checkChi("!!!!!!!!!!!!!!!!!!!") result = self.chi.checkChi("!!!!!!!!!!!!!!!!!!!")
self.assertEqual(result, True) self.assertEqual(result, True)
def tests_english_overflow(self): def tests_english_overflow(self):
self.chi = chisquared.chiSquared() self.chi = app.languageCheckerMod.chisquared.chiSquared()
""" """
Tests to see whether a sentene is classified as English or not Tests to see whether a sentene is classified as English or not
""" """
@ -48,7 +48,7 @@ class TestChi(unittest.TestCase):
result = self.chi.checkChi("cguakdbwnmfqknm ") result = self.chi.checkChi("cguakdbwnmfqknm ")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_english_quckbrown(self): def test_english_quckbrown(self):
self.chi = chisquared.chiSquared() self.chi = app.languageCheckerMod.chisquared.chiSquared()
""" """
Tests to see whether a sentene is classified as English or not Tests to see whether a sentene is classified as English or not
""" """
@ -66,7 +66,7 @@ class TestChi(unittest.TestCase):
result = self.chi.checkChi("The quick brown fox jumped over the lazy dog") result = self.chi.checkChi("The quick brown fox jumped over the lazy dog")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_english_puncuation(self): def test_english_puncuation(self):
self.chi = chisquared.chiSquared() self.chi = app.languageCheckerMod.chisquared.chiSquared()
""" """
Tests to see whether a sentene is classified as English or not Tests to see whether a sentene is classified as English or not
Returns False because exclamation marks aren't english Returns False because exclamation marks aren't english
@ -85,7 +85,7 @@ class TestChi(unittest.TestCase):
result = self.chi.checkChi("!!!!!!!!!!!!!!!!!!!!!!") result = self.chi.checkChi("!!!!!!!!!!!!!!!!!!!!!!")
self.assertEqual(result, True) self.assertEqual(result, True)
def test_english_one_letter(self): def test_english_one_letter(self):
self.chi = chisquared.chiSquared() self.chi = app.languageCheckerMod.chisquared.chiSquared()
""" """
Tests to see whether a sentene is classified as English or not Tests to see whether a sentene is classified as English or not
Returns False because exclamation marks aren't english Returns False because exclamation marks aren't english
@ -104,7 +104,7 @@ class TestChi(unittest.TestCase):
result = self.chi.checkChi("a") result = self.chi.checkChi("a")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_english_same_letter(self): def test_english_same_letter(self):
self.chi = chisquared.chiSquared() self.chi = app.languageCheckerMod.chisquared.chiSquared()
""" """
Tests to see whether a sentene is classified as English or not Tests to see whether a sentene is classified as English or not
Returns False because exclamation marks aren't english Returns False because exclamation marks aren't english
@ -123,7 +123,7 @@ class TestChi(unittest.TestCase):
result = self.chi.checkChi("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz") result = self.chi.checkChi("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_english_same_letter(self): def test_english_same_letter(self):
self.chi = chisquared.chiSquared() self.chi = app.languageCheckerMod.chisquared.chiSquared()
""" """
Tests to see whether a sentene is classified as English or not Tests to see whether a sentene is classified as English or not
Returns False because exclamation marks aren't english Returns False because exclamation marks aren't english
@ -142,7 +142,7 @@ class TestChi(unittest.TestCase):
result = self.chi.checkChi("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz") result = self.chi.checkChi("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_my_chi(self): def test_my_chi(self):
self.chi = chisquared.chiSquared() self.chi = app.languageCheckerMod.chisquared.chiSquared()
result = self.chi.myChi(self.chi.getLetterFreq("hello this is my test"), [0.0812, 0.0271, 0.0149, 0.1202, 0.0432, 0.0203, 0.023, 0.0731, 0.0592, 0.0069, 0.001, 0.026099999999999998, 0.0398, 0.0768, 0.0695, 0.0011, 0.0182, 0.06280000000000001, 0.0602, 0.0288, 0.091, 0.0209, 0.0111, 0.021099999999999997, 0.0017000000000000001, 0.0007000000000000001]) result = self.chi.myChi(self.chi.getLetterFreq("hello this is my test"), [0.0812, 0.0271, 0.0149, 0.1202, 0.0432, 0.0203, 0.023, 0.0731, 0.0592, 0.0069, 0.001, 0.026099999999999998, 0.0398, 0.0768, 0.0695, 0.0011, 0.0182, 0.06280000000000001, 0.0602, 0.0288, 0.091, 0.0209, 0.0111, 0.021099999999999997, 0.0017000000000000001, 0.0007000000000000001])
self.assertEqual(result, 1424.8873999810571) self.assertEqual(result, 1424.8873999810571)

View File

@ -1,24 +1,24 @@
import sys import sys
sys.path.append("..") sys.path.append("..")
import unittest import unittest
from languageCheckerMod.languageChecker import LanguageChecker import app.languageCheckerMod.LanguageChecker
# python3 -m unittest Tests.testchi_squared # python3 -m unittest Tests.testchi_squared
# python -m unittest discover -s tests # python -m unittest discover -s tests
# python3 -m unittest discover -s Tests -p test*.py # python3 -m unittest discover -s Tests -p test*.py
class TestLanguageChecker(unittest.TestCase): class TestLanguageChecker(unittest.TestCase):
def test_basics(self): def test_basics(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("Hello my name is new and this is an example of some english text") result = lc.checkLanguage("Hello my name is new and this is an example of some english text")
self.assertEqual(result, True) self.assertEqual(result, True)
def test_basics_german(self): def test_basics_german(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("hallo keine lieben leute nach") result = lc.checkLanguage("hallo keine lieben leute nach")
self.assertEqual(result, True) self.assertEqual(result, True)
def test_basics_quickbrownfox(self): def test_basics_quickbrownfox(self):
""" """
This returns true becaue by default chi squared returns true so long as it's less than 10 items it's processed This returns true becaue by default chi squared returns true so long as it's less than 10 items it's processed
""" """
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("The quick brown fox jumped over the lazy dog") result = lc.checkLanguage("The quick brown fox jumped over the lazy dog")
self.assertEqual(result, True) self.assertEqual(result, True)
def test_basics_quickbrownfox(self): def test_basics_quickbrownfox(self):
@ -29,7 +29,7 @@ class TestLanguageChecker(unittest.TestCase):
result = lc.checkLanguage("The quick brown fox jumped over the lazy dog") result = lc.checkLanguage("The quick brown fox jumped over the lazy dog")
self.assertEqual(result, True) self.assertEqual(result, True)
def test_chi_maxima(self): def test_chi_maxima(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("The quick brown fox jumped over the lazy dog") result = lc.checkLanguage("The quick brown fox jumped over the lazy dog")
result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.") result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.")
result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.") result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.")
@ -46,7 +46,7 @@ class TestLanguageChecker(unittest.TestCase):
result = lc.checkLanguage("The quick brown fox jumped over the lazy dog") result = lc.checkLanguage("The quick brown fox jumped over the lazy dog")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_chi_maxima_false(self): def test_chi_maxima_false(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("The quick brown fox jumped over the lazy dog") result = lc.checkLanguage("The quick brown fox jumped over the lazy dog")
result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.") result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.")
result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.") result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.")
@ -66,7 +66,7 @@ class TestLanguageChecker(unittest.TestCase):
""" """
This returns false because s.d is not over 1 as all inputs are English This returns false because s.d is not over 1 as all inputs are English
""" """
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("The quick brown fox jumped over the lazy dog") result = lc.checkLanguage("The quick brown fox jumped over the lazy dog")
result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.") result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.")
result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.") result = lc.checkLanguage("Hypertext Transfer Protocol (HTTP) parameters, including HTTP headers, allow the client and the server to pass additional information with the request or the response.")
@ -86,7 +86,7 @@ class TestLanguageChecker(unittest.TestCase):
""" """
This returns false because s.d is not over 1 as all inputs are English This returns false because s.d is not over 1 as all inputs are English
""" """
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("sa dew fea dxza dcsa da fsa d") result = lc.checkLanguage("sa dew fea dxza dcsa da fsa d")
result = lc.checkLanguage("df grtsf a sgrds fgserwqd") result = lc.checkLanguage("df grtsf a sgrds fgserwqd")
result = lc.checkLanguage("fd sa fe safsda srmad sadsa d") result = lc.checkLanguage("fd sa fe safsda srmad sadsa d")
@ -103,49 +103,49 @@ class TestLanguageChecker(unittest.TestCase):
result = lc.checkLanguage("My friend is a really nice people who really enjoys swimming, dancing, kicking, English.") result = lc.checkLanguage("My friend is a really nice people who really enjoys swimming, dancing, kicking, English.")
self.assertEqual(result, True) self.assertEqual(result, True)
def test_integration_unusual_one(self): def test_integration_unusual_one(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("HELLO MY NAME IS BRANDON AND I LIKE DOLLAR") result = lc.checkLanguage("HELLO MY NAME IS BRANDON AND I LIKE DOLLAR")
self.assertEqual(result, True) self.assertEqual(result, True)
def test_integration_unusual_two(self): def test_integration_unusual_two(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") result = lc.checkLanguage("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_integration_unusual_three(self): def test_integration_unusual_three(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("password") result = lc.checkLanguage("password")
self.assertEqual(result, True) self.assertEqual(result, True)
def test_integration_unusual_three(self): def test_integration_unusual_three(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("") result = lc.checkLanguage("")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_integration_unusual_four(self): def test_integration_unusual_four(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage(".") result = lc.checkLanguage(".")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_integration_unusual_five(self): def test_integration_unusual_five(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("#") result = lc.checkLanguage("#")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_integration_unusual_6(self): def test_integration_unusual_6(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("\"") result = lc.checkLanguage("\"")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_integration_unusual_7(self): def test_integration_unusual_7(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999") result = lc.checkLanguage("999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_integration_unusual_7(self): def test_integration_unusual_7(self):
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("") result = lc.checkLanguage("")
self.assertEqual(result, False) self.assertEqual(result, False)
def test_integration_addition(self): def test_integration_addition(self):
""" """
Makes sure you can add 2 lanuggae objecs together Makes sure you can add 2 lanuggae objecs together
""" """
lc = LanguageChecker() lc = app.languageCheckerMod.LanguageChecker.LanguageChecker()
result = lc.checkLanguage("hello my darling") result = lc.checkLanguage("hello my darling")
lc2 = LanguageChecker() lc2 = app.LanguageChecker()
result = lc.checkLanguage("sad as dasr as s") result = lc.checkLanguage("sad as dasr as s")
temp = lc.getChiScore() temp = lc.getChiScore()

View File

@ -1,7 +1,7 @@
import sys import sys
sys.path.append("..") sys.path.append("..")
import unittest import unittest
from neuralNetworkMod.nn import NeuralNetwork import app.neuralNetworkMod.nn
import numpy import numpy
# python3 -m unittest Tests.testchi_squared # python3 -m unittest Tests.testchi_squared
# python -m unittest discover -s tests # python -m unittest discover -s tests
@ -11,31 +11,31 @@ import numpy
class TestNN(unittest.TestCase): class TestNN(unittest.TestCase):
def test_english_yes(self): def test_english_yes(self):
"""Checks to see if it returns True (it should)""" """Checks to see if it returns True (it should)"""
model = NeuralNetwork() model = app.neuralNetworkMod.nn.NeuralNetwork()
result = model.predictnn("bcpvu up qvu ifs cpplt bxbz, cvu jotufbe tif qvmmfe") result = model.predictnn("bcpvu up qvu ifs cpplt bxbz, cvu jotufbe tif qvmmfe")
numpy.set_printoptions(suppress=True) numpy.set_printoptions(suppress=True)
result = numpy.argmax(result) result = numpy.argmax(result)
self.assertEqual(result, 4) self.assertEqual(result, 4)
def test_sha1_yes(self): def test_sha1_yes(self):
model = NeuralNetwork() model = app.neuralNetworkMod.nn.NeuralNetwork()
result = model.predictnn("6D32263A85C7846D70439026B75758C9FC31A9B7") result = model.predictnn("6D32263A85C7846D70439026B75758C9FC31A9B7")
numpy.set_printoptions(suppress=True) numpy.set_printoptions(suppress=True)
result = numpy.argmax(result) result = numpy.argmax(result)
self.assertEqual(result, 0) self.assertEqual(result, 0)
def test_md5_yes(self): def test_md5_yes(self):
model = NeuralNetwork() model = app.neuralNetworkMod.nn.NeuralNetwork()
result = model.predictnn("5d41402abc4b2a76b9719d911017c592") result = model.predictnn("5d41402abc4b2a76b9719d911017c592")
numpy.set_printoptions(suppress=True) numpy.set_printoptions(suppress=True)
result = numpy.argmax(result) result = numpy.argmax(result)
self.assertEqual(result, 1) self.assertEqual(result, 1)
def test_sha512_yes(self): def test_sha512_yes(self):
model = NeuralNetwork() model = app.neuralNetworkMod.nn.NeuralNetwork()
result = model.predictnn("9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043") result = model.predictnn("9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043")
numpy.set_printoptions(suppress=True) numpy.set_printoptions(suppress=True)
result = numpy.argmax(result) result = numpy.argmax(result)
self.assertEqual(result, 3) self.assertEqual(result, 3)
def test_caesar_yes(self): def test_caesar_yes(self):
model = NeuralNetwork() model = app.neuralNetworkMod.nn.NeuralNetwork()
result = model.predictnn("bcpvu up qvu ifs cpplt bxbz, cvu jotufbe tif qvmmfe") result = model.predictnn("bcpvu up qvu ifs cpplt bxbz, cvu jotufbe tif qvmmfe")
numpy.set_printoptions(suppress=True) numpy.set_printoptions(suppress=True)
result = numpy.argmax(result) result = numpy.argmax(result)

View File

@ -210,7 +210,7 @@ if __name__ == "__main__":
#parser.add_argument('-g','--greppable', help='Are you grepping this output?', required=False) #parser.add_argument('-g','--greppable', help='Are you grepping this output?', required=False)
parser.add_argument('-t','--text', help='Text to decrypt', required=False) parser.add_argument('-t','--text', help='Text to decrypt', required=False)
#parser.add_argument('-s','--sicko-mode', help='If it is encrypted Ciphey WILL find it', required=False) #parser.add_argument('-s','--sicko-mode', help='If it is encrypted Ciphey WILL find it', required=False)
#parser.add_argument('-c','--cipher', help='What is the cipher used?', required=False) parser.add_argument('-c','--cipher', help='What is the cipher used?', required=False)
args = vars(parser.parse_args()) args = vars(parser.parse_args())
if args['cipher'] != None: if args['cipher'] != None:

View File

@ -46,19 +46,22 @@ In alphabetical order
And you're.... Done! Make sure the name of the two match up And you're.... Done! Make sure the name of the two match up
""" """
from string import punctuation from string import punctuation
#import mathsHelper import app.languageCheckerMod.dictionaryChecker
import languageCheckerMod.dictionaryChecker import app.languageCheckerMod.chisquared
import languageCheckerMod.chisquared from app import languageCheckerMod
class LanguageChecker: class LanguageChecker:
def __init__(self): def __init__(self):
self.dictionary = languageCheckerMod.dictionaryChecker.dictionaryChecker() self.dictionary = languageCheckerMod.dictionaryChecker.dictionaryChecker()
self.chi = languageCheckerMod.chisquared.chiSquared() self.chi = languageCheckerMod.chisquared.chiSquared()
def __add__(self, otherLanguageObject): def __add__(self, otherLanguageObject):
# sets the added chi squared to be of this one # sets the added chi squared to be of this one
new = otherLanguageObject.getChiSquaredObj() + self.getChiSquaredObj() new = otherLanguageObject.getChiSquaredObj() + self.getChiSquaredObj()
self.chi = new self.chi = new
return self return self
def checkLanguage(self, text): def checkLanguage(self, text):
if text == "": if text == "":
return False return False
@ -71,7 +74,9 @@ class LanguageChecker:
return False return False
else: else:
return False return False
def getChiSquaredObj(self): def getChiSquaredObj(self):
return self.chi return self.chi
def getChiScore(self): def getChiScore(self):
return self.chi.totalChi return self.chi.totalChi

View File

@ -10,7 +10,7 @@ Github: brandonskerritt
Class calculates the Chi squared score Class calculates the Chi squared score
""" """
import mathsHelper import app.mathsHelper
from string import punctuation from string import punctuation
from numpy import std from numpy import std
# I had a bug where empty string was being added to letter freq dictionary # I had a bug where empty string was being added to letter freq dictionary
@ -32,7 +32,7 @@ class chiSquared:
self.average = 0.0 self.average = 0.0
self.totalDone = 0.0 self.totalDone = 0.0
self.oldAverage = 0.0 self.oldAverage = 0.0
self.mh = mathsHelper.mathsHelper() self.mh = app.mathsHelper.mathsHelper()
self.highestLanguage = "" self.highestLanguage = ""
self.totalChi = 0.0 self.totalChi = 0.0
self.totalEqual = False self.totalEqual = False

View File

@ -1,4 +1,4 @@
import mathsHelper import app.mathsHelper
import string import string
class dictionaryChecker: class dictionaryChecker:
""" """
@ -12,10 +12,11 @@ class dictionaryChecker:
if a string is 45% **language** words, then it's confirmed to be english if a string is 45% **language** words, then it's confirmed to be english
""" """
def __init__(self): def __init__(self):
self.mh = mathsHelper.mathsHelper() self.mh = app.mathsHelper.mathsHelper()
self.languagePercentage = 0.0 self.languagePercentage = 0.0
self.languageWordsCounter = 0.0 self.languageWordsCounter = 0.0
self.languageThreshold = 55 self.languageThreshold = 55
def checkDictionary(self, text, language): def checkDictionary(self, text, language):
"""Compares a word with """Compares a word with
The dictionary is sorted and the text is sorted""" The dictionary is sorted and the text is sorted"""
@ -49,7 +50,7 @@ class dictionaryChecker:
so we only loop once, we can do this in O(n log n) time so we only loop once, we can do this in O(n log n) time
""" """
counter = 0 counter = 0
counterPercent = 0 counter_percent = 0
for dictLengthCounter, word in enumerate(f): for dictLengthCounter, word in enumerate(f):
# if there is more words counted than there is text # if there is more words counted than there is text
@ -61,10 +62,10 @@ class dictionaryChecker:
# counter + 1 # counter + 1
if word in text: if word in text:
counter = counter + 1 counter = counter + 1
counterPercent = counterPercent + 1 counter_percent = counter_percent + 1
self.languageWordsCounter = counter self.languageWordsCounter = counter
self.languagePercentage = self.mh.percentage(float(self.languageWordsCounter), float(len(text))) self.languagePercentage = self.mh.percentage(float(self.languageWordsCounter), float(len(text)))
return(counter) return counter
def confirmlanguage(self, text, language): def confirmlanguage(self, text, language):
self.checkDictionary(text, language) self.checkDictionary(text, language)
@ -72,4 +73,3 @@ class dictionaryChecker:
return True return True
else: else:
return False return False

7
license Normal file
View File

@ -0,0 +1,7 @@
Copyright 2020 Brandon Skerritt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

42
setup.py Normal file
View File

@ -0,0 +1,42 @@
import pathlib
from setuptools import setup, find_packages
import io
import os
# The directory containing this file
HERE = pathlib.Path(__file__).parent
# The text of the README file
README = (HERE / "README.MD").read_text()
long_description = "An automated decryption tool using machine learning"
DESCRIPTION = "An automated decryption tool using machine learning"
# get list of required installs
with open('requirements.txt') as f:
required = f.read().splitlines()
# This call to setup() does all the work
setup(
name="ciphey",
version="2.0.0",
description="Automated decryption tool using machine learning & common sense",
long_description=README,
long_description_content_type="text/markdown",
url="https://github.com/brandonskerritt/ciphey",
author="Brandon Skerritt",
author_email="brandon@skerritt.blog",
license="MIT",
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
],
packages=find_packages(exclude=("tests",)),
include_package_data=True,
install_requires=required,
entry_points={
"console_scripts": [
"ciphey=app.__main__:main",
]
},
)