Skip to content

Commit 59ff4cf

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 78c53a8 commit 59ff4cf

10 files changed

Lines changed: 66 additions & 21 deletions

ciphers/adfgvx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
The ADFGVX cipher uses a 6x6 Polybius square (A-Z + 0-9) and a columnar
99
transposition with a keyword.
1010
"""
11+
1112
from __future__ import annotations
1213

1314
import argparse
@@ -58,7 +59,7 @@ def columnar_transpose_encrypt(text: str, key: str) -> str:
5859
key = "".join(ch for ch in key.upper() if ch.isalnum())
5960
order = sorted(range(len(key)), key=lambda i: (key[i], i))
6061
rows = math.ceil(len(text) / len(key))
61-
grid = [list(text[i * len(key):(i + 1) * len(key)]) for i in range(rows)]
62+
grid = [list(text[i * len(key) : (i + 1) * len(key)]) for i in range(rows)]
6263
if grid:
6364
last = grid[-1]
6465
while len(last) < len(key):

ciphers/adfgx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
The ADFGX cipher uses a 5x5 Polybius square (I/J merged) and a columnar
99
transposition with a keyword.
1010
"""
11+
1112
from __future__ import annotations
1213

1314
import argparse
@@ -60,7 +61,7 @@ def columnar_transpose_encrypt(text: str, key: str) -> str:
6061
key = "".join(ch for ch in key.upper() if ch.isalpha())
6162
order = sorted(range(len(key)), key=lambda i: (key[i], i))
6263
rows = math.ceil(len(text) / len(key))
63-
grid = [list(text[i * len(key):(i + 1) * len(key)]) for i in range(rows)]
64+
grid = [list(text[i * len(key) : (i + 1) * len(key)]) for i in range(rows)]
6465
# Pad with X
6566
if grid:
6667
last = grid[-1]

ciphers/four_square_cipher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
This is a digraph substitution cipher using four 5x5 squares with I/J merged.
99
"""
10+
1011
from __future__ import annotations
1112

1213
import argparse

cyber_security/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,3 @@
2020
"file_integrity_monitor",
2121
"url_analyzer",
2222
]
23-
24-

cyber_security/file_integrity_monitor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
python -m cyber_security.file_integrity_monitor init --root /path --output baseline.json --glob "**/*.py"
1010
python -m cyber_security.file_integrity_monitor verify --root /path --baseline baseline.json
1111
"""
12+
1213
from __future__ import annotations
1314

1415
import argparse
@@ -106,7 +107,9 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
106107
p_init = sub.add_parser("init", help="Create baseline JSON of file hashes")
107108
p_init.add_argument("--root", required=True, help="Root directory to scan")
108109
p_init.add_argument("--output", required=True, help="Path to baseline JSON output")
109-
p_init.add_argument("--glob", help="Glob-like pattern relative to root (e.g., **/*.py)")
110+
p_init.add_argument(
111+
"--glob", help="Glob-like pattern relative to root (e.g., **/*.py)"
112+
)
110113
p_init.set_defaults(func=cmd_init)
111114

112115
p_ver = sub.add_parser("verify", help="Verify current state against baseline JSON")

cyber_security/hash_cracker.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Usage:
55
python -m cyber_security.hash_cracker --algo sha256 --hash <hash> --wordlist words.txt
66
"""
7+
78
from __future__ import annotations
89

910
import argparse
@@ -39,10 +40,14 @@ def crack_hash(target_hash: str, algo: str, wordlist_path: str) -> str | None:
3940

4041
def parse_args(argv: list[str]) -> argparse.Namespace:
4142
parser = argparse.ArgumentParser(description="Hash cracker using a wordlist.")
42-
parser.add_argument("--algo", choices=sorted(ALGORITHMS), default="sha256", help="Hash algorithm")
43+
parser.add_argument(
44+
"--algo", choices=sorted(ALGORITHMS), default="sha256", help="Hash algorithm"
45+
)
4346
parser.add_argument("--hash", required=True, help="Target hex digest")
4447
parser.add_argument("--wordlist", required=True, help="Path to wordlist file")
45-
parser.add_argument("--quiet", action="store_true", help="Only print the cracked password if found")
48+
parser.add_argument(
49+
"--quiet", action="store_true", help="Only print the cracked password if found"
50+
)
4651
return parser.parse_args(argv)
4752

4853

cyber_security/password_strength_checker.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
python -m cyber_security.password_strength_checker "P@ssw0rd!"
66
python -m cyber_security.password_strength_checker --help
77
"""
8+
89
from __future__ import annotations
910

1011
import argparse
@@ -99,14 +100,27 @@ def uses(charset: str) -> bool:
99100
if re.search(r"(\d){4,}", password):
100101
feedback.append("Avoid long digit sequences.")
101102

102-
estimated_space = int(2 ** entropy) if entropy < 60 else int(10 ** (entropy / math.log2(10)))
103+
estimated_space = (
104+
int(2**entropy) if entropy < 60 else int(10 ** (entropy / math.log2(10)))
105+
)
103106
return StrengthResult(entropy, estimated_space, category, feedback)
104107

105108

106109
def parse_args(argv: list[str]) -> argparse.Namespace:
107-
parser = argparse.ArgumentParser(description="Estimate password strength and provide feedback.")
108-
parser.add_argument("password", nargs="?", help="Password string to evaluate. If omitted, read from stdin.")
109-
parser.add_argument("-q", "--quiet", action="store_true", help="Print only the entropy and category.")
110+
parser = argparse.ArgumentParser(
111+
description="Estimate password strength and provide feedback."
112+
)
113+
parser.add_argument(
114+
"password",
115+
nargs="?",
116+
help="Password string to evaluate. If omitted, read from stdin.",
117+
)
118+
parser.add_argument(
119+
"-q",
120+
"--quiet",
121+
action="store_true",
122+
help="Print only the entropy and category.",
123+
)
110124
return parser.parse_args(argv)
111125

112126

cyber_security/port_scanner.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Usage:
55
python -m cyber_security.port_scanner 192.168.1.10 --ports 1-1024 --threads 200 --timeout 0.5 --banner
66
"""
7+
78
from __future__ import annotations
89

910
import argparse
@@ -68,12 +69,25 @@ def try_connect(host: str, port: int, timeout: float, banner: bool) -> ScanResul
6869

6970

7071
def parse_args(argv: list[str]) -> argparse.Namespace:
71-
parser = argparse.ArgumentParser(description="TCP port scanner with multi-threading and banner grab.")
72+
parser = argparse.ArgumentParser(
73+
description="TCP port scanner with multi-threading and banner grab."
74+
)
7275
parser.add_argument("host", help="Target IPv4/hostname")
73-
parser.add_argument("--ports", default="1-1024", help="Port spec, e.g., 1-1024,22,80,443")
74-
parser.add_argument("--threads", type=int, default=DEFAULT_THREADS, help="Max worker threads")
75-
parser.add_argument("--timeout", type=float, default=DEFAULT_TIMEOUT, help="Socket timeout in seconds")
76-
parser.add_argument("--banner", action="store_true", help="Attempt to grab service banner")
76+
parser.add_argument(
77+
"--ports", default="1-1024", help="Port spec, e.g., 1-1024,22,80,443"
78+
)
79+
parser.add_argument(
80+
"--threads", type=int, default=DEFAULT_THREADS, help="Max worker threads"
81+
)
82+
parser.add_argument(
83+
"--timeout",
84+
type=float,
85+
default=DEFAULT_TIMEOUT,
86+
help="Socket timeout in seconds",
87+
)
88+
parser.add_argument(
89+
"--banner", action="store_true", help="Attempt to grab service banner"
90+
)
7791
return parser.parse_args(argv)
7892

7993

@@ -94,9 +108,12 @@ def main(argv: list[str] | None = None) -> int:
94108

95109
tasks: list[Tuple[str, int]] = [(host, p) for p in ports]
96110

97-
with concurrent.futures.ThreadPoolExecutor(max_workers=max(1, args.threads)) as executor:
111+
with concurrent.futures.ThreadPoolExecutor(
112+
max_workers=max(1, args.threads)
113+
) as executor:
98114
future_to_port = {
99-
executor.submit(try_connect, host, port, args.timeout, args.banner): port for _, port in tasks
115+
executor.submit(try_connect, host, port, args.timeout, args.banner): port
116+
for _, port in tasks
100117
}
101118
for future in concurrent.futures.as_completed(future_to_port):
102119
res = future.result()

cyber_security/url_analyzer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Usage:
55
python -m cyber_security.url_analyzer https://example.com
66
"""
7+
78
from __future__ import annotations
89

910
import argparse
@@ -105,9 +106,13 @@ def analyze(url: str) -> list[str]:
105106

106107

107108
def parse_args(argv: list[str]) -> argparse.Namespace:
108-
parser = argparse.ArgumentParser(description="Analyze a URL for phishing/IDN risks.")
109+
parser = argparse.ArgumentParser(
110+
description="Analyze a URL for phishing/IDN risks."
111+
)
109112
parser.add_argument("url", help="URL to analyze")
110-
parser.add_argument("--quiet", action="store_true", help="Exit code only: 0 safe-ish, 1 suspicious")
113+
parser.add_argument(
114+
"--quiet", action="store_true", help="Exit code only: 0 safe-ish, 1 suspicious"
115+
)
111116
return parser.parse_args(argv)
112117

113118

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
beautifulsoup4
22
fake-useragent
33
httpx
4+
idna
45
imageio
56
keras
67
lxml
@@ -17,4 +18,3 @@ sympy
1718
tweepy
1819
typing_extensions
1920
xgboost
20-
idna

0 commit comments

Comments
 (0)