Skip to content

Commit 35e3de8

Browse files
Merge pull request #619 from Ciphey/bee-fix-ausearch
Added new checker and general cleanup
2 parents 85d306d + 24b8412 commit 35e3de8

File tree

8 files changed

+67
-22
lines changed

8 files changed

+67
-22
lines changed

ciphey/basemods/Checkers/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from . import any, brandon, ezcheck, format, human, quorum, regex
1+
from . import any, brandon, ezcheck, format, human, quorum, regex, what

ciphey/basemods/Checkers/brandon.py

-12
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,6 @@ def clean_text(self, text: str) -> set:
104104
text = set(text)
105105
return text
106106

107-
x = []
108-
for word in text:
109-
# poor mans lemmatisation
110-
# removes 's from the dict'
111-
if word.endswith("'s"):
112-
x.append(word[0:-2])
113-
text = self.mh.strip_punctuation(x)
114-
# turns it all into lowercase and as a set
115-
complete = set([word.lower() for word in x])
116-
117-
return complete
118-
119107
def checker(self, text: str, threshold: float, text_length: int, var: set) -> bool:
120108
"""Given text determine if it passes checker
121109

ciphey/basemods/Checkers/ezcheck.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .format import JsonChecker
77
from .human import HumanChecker
88
from .regex import RegexList
9+
from .what import What
910

1011

1112
@registry.register
@@ -41,11 +42,8 @@ def __init__(self, config: Config):
4142

4243
# We need to modify the config for each of the objects
4344

44-
# First the flag regexes, as they are the fastest
45-
flags_config = config
46-
flags_config.update_param("regexlist", "resource", "cipheydists::list::flags")
47-
# We do not cache, as this uses a different, on-time config
48-
self.checkers.append(RegexList(flags_config))
45+
# First PyWhat, as it's the fastest
46+
self.checkers.append(config(What))
4947

5048
# Next, the json checker
5149
self.checkers.append(config(JsonChecker))

ciphey/basemods/Checkers/what.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from typing import Dict, Optional
2+
3+
from ciphey.iface import Checker, Config, ParamSpec, T, registry
4+
from loguru import logger
5+
from pywhat import identifier
6+
7+
8+
@registry.register
9+
class What(Checker[str]):
10+
11+
"""
12+
Uses PyWhat to determine plaintext with regexes
13+
"""
14+
15+
def check(self, ctext: T) -> Optional[str]:
16+
logger.trace("Trying PyWhat checker")
17+
returned_regexes = self.id.identify(ctext, api=True)
18+
if len(returned_regexes["Regexes"]) > 0:
19+
return returned_regexes["Regexes"][0]["Regex Pattern"]["Name"]
20+
return None
21+
22+
def getExpectedRuntime(self, text: T) -> float:
23+
# TODO: actually bench this
24+
return 2e-7 * len(text)
25+
26+
@staticmethod
27+
def getParams() -> Optional[Dict[str, ParamSpec]]:
28+
return None
29+
30+
def __init__(self, config: Config):
31+
super().__init__(config)
32+
self.id = identifier.Identifier()

ciphey/basemods/Searchers/ausearch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,4 @@ def getParams() -> Optional[Dict[str, ParamSpec]]:
337337
desc="Sets the maximum depth before we give up ordering items.",
338338
default="2",
339339
),
340-
}
340+
}

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "ciphey"
3-
version = "5.11.2"
3+
version = "5.11.3"
44
description = "Automated Decryption Tool"
55
authors = ["Brandon <[email protected]>"]
66
license = "MIT"
@@ -25,6 +25,7 @@ click = ">=7.1.2,<9.0.0"
2525
click-spinner = "^0.1.10"
2626
pyyaml = "^5.3.1"
2727
yaspin = ">=0.17,<1.6"
28+
pywhat = "^0.2.5"
2829

2930
[tool.poetry.dev-dependencies]
3031
pytest-cov = "^2.10.1"

tests/test_main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def test_binary_base64_caesar():
123123

124124
def test_braille():
125125
res = decrypt(
126-
Config.library_default().complete_config(),
127-
"⠓⠑⠇⠇⠕⠀⠍⠽⠀⠝⠁⠍⠑⠀⠊⠎⠀⠃⠑⠑⠀⠁⠝⠙⠀⠊⠀⠇⠊⠅⠑⠀⠙⠕⠛⠀⠁⠝⠙⠀⠁⠏⠏⠇⠑⠀⠁⠝⠙⠀⠞⠗⠑⠑"
126+
Config.library_default().complete_config(),
127+
"⠓⠑⠇⠇⠕⠀⠍⠽⠀⠝⠁⠍⠑⠀⠊⠎⠀⠃⠑⠑⠀⠁⠝⠙⠀⠊⠀⠇⠊⠅⠑⠀⠙⠕⠛⠀⠁⠝⠙⠀⠁⠏⠏⠇⠑⠀⠁⠝⠙⠀⠞⠗⠑⠑",
128128
)
129129
assert res.lower() == answer_str.lower()
130130

tests/test_regex.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pytest
2+
3+
from ciphey import decrypt
4+
from ciphey.iface import Config
5+
6+
7+
def test_regex_ip():
8+
res = decrypt(
9+
Config().library_default().complete_config(),
10+
"MTkyLjE2MC4wLjE=",
11+
)
12+
assert res == "192.160.0.1"
13+
14+
def test_regex_domain():
15+
res = decrypt(
16+
Config().library_default().complete_config(),
17+
"aHR0cHM6Ly9nb29nbGUuY29t",
18+
)
19+
assert res == "https://google.com"
20+
21+
def test_regex_bitcoin():
22+
res = decrypt(
23+
Config().library_default().complete_config(),
24+
"M0ZaYmdpMjljcGpxMkdqZHdWOGV5SHVKSm5rTHRrdFpjNQ==",
25+
)
26+
assert res == "3FZbgi29cpjq2GjdwV8eyHuJJnkLtktZc5"

0 commit comments

Comments
 (0)