decryptre 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {decryptre-0.1.0 → decryptre-0.2.0}/PKG-INFO +28 -1
  2. {decryptre-0.1.0 → decryptre-0.2.0}/README.md +27 -0
  3. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/__init__.py +1 -1
  4. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/cli.py +11 -1
  5. decryptre-0.2.0/decryptre/interactive.py +427 -0
  6. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre.egg-info/PKG-INFO +28 -1
  7. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre.egg-info/SOURCES.txt +2 -0
  8. {decryptre-0.1.0 → decryptre-0.2.0}/pyproject.toml +1 -1
  9. decryptre-0.2.0/tests/test_interactive.py +28 -0
  10. {decryptre-0.1.0 → decryptre-0.2.0}/LICENSE +0 -0
  11. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/__main__.py +0 -0
  12. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/auto_detect.py +0 -0
  13. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/classical.py +0 -0
  14. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/containers.py +0 -0
  15. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/data/SOURCE.md +0 -0
  16. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/data/trigrams.txt +0 -0
  17. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/encodings.py +0 -0
  18. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/models.py +0 -0
  19. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/modern_crypto.py +0 -0
  20. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/ngrams.py +0 -0
  21. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/scorer.py +0 -0
  22. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/wordlists/SOURCE.md +0 -0
  23. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/wordlists/common-passwords.txt +0 -0
  24. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre/xor.py +0 -0
  25. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre.egg-info/dependency_links.txt +0 -0
  26. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre.egg-info/entry_points.txt +0 -0
  27. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre.egg-info/requires.txt +0 -0
  28. {decryptre-0.1.0 → decryptre-0.2.0}/decryptre.egg-info/top_level.txt +0 -0
  29. {decryptre-0.1.0 → decryptre-0.2.0}/setup.cfg +0 -0
  30. {decryptre-0.1.0 → decryptre-0.2.0}/tests/test_auto_detect.py +0 -0
  31. {decryptre-0.1.0 → decryptre-0.2.0}/tests/test_classical.py +0 -0
  32. {decryptre-0.1.0 → decryptre-0.2.0}/tests/test_cli.py +0 -0
  33. {decryptre-0.1.0 → decryptre-0.2.0}/tests/test_encodings.py +0 -0
  34. {decryptre-0.1.0 → decryptre-0.2.0}/tests/test_modern_crypto.py +0 -0
  35. {decryptre-0.1.0 → decryptre-0.2.0}/tests/test_offline.py +0 -0
  36. {decryptre-0.1.0 → decryptre-0.2.0}/tests/test_scorer.py +0 -0
  37. {decryptre-0.1.0 → decryptre-0.2.0}/tests/test_xor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: decryptre
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Offline, open-source CLI that decrypts text with or without a passphrase and re-encrypts it with the same methods.
5
5
  Author: Jason Marvello
6
6
  License-Expression: MIT
@@ -74,6 +74,14 @@ Two honest statements that the code and docs repeat:
74
74
 
75
75
  Requirements: **Python 3.9 or newer**.
76
76
 
77
+ The quickest way is from PyPI:
78
+
79
+ ```bash
80
+ pip install decryptre
81
+ ```
82
+
83
+ Or install from source:
84
+
77
85
  ```bash
78
86
  git clone https://github.com/JasonMarvello/DecryptRE.git
79
87
  cd DecryptRE
@@ -115,6 +123,25 @@ standard input.
115
123
 
116
124
  ---
117
125
 
126
+ ## Interactive mode
127
+
128
+ Run it with no arguments and you get a menu instead of flags:
129
+
130
+ ```bash
131
+ decryptre
132
+ ```
133
+
134
+ Arrow keys (or `j`/`k`) move, `1`-`6` jump straight to an option, Enter
135
+ selects, `q` goes back and Ctrl+C quits. Choose **Decrypt / decode text**,
136
+ paste ciphertext or a file path, optionally give a passphrase, then pick from
137
+ the ranked results and ask for another layer if the text is still encoded.
138
+ Encrypt and identify work the same way.
139
+
140
+ `decryptre --help` still prints the full command reference, and when input is
141
+ piped (`cat cipher.txt | decryptre`) the help is printed instead of the menu.
142
+
143
+ ---
144
+
118
145
  ## Commands
119
146
 
120
147
  ### `decryptre decrypt`
@@ -52,6 +52,14 @@ Two honest statements that the code and docs repeat:
52
52
 
53
53
  Requirements: **Python 3.9 or newer**.
54
54
 
55
+ The quickest way is from PyPI:
56
+
57
+ ```bash
58
+ pip install decryptre
59
+ ```
60
+
61
+ Or install from source:
62
+
55
63
  ```bash
56
64
  git clone https://github.com/JasonMarvello/DecryptRE.git
57
65
  cd DecryptRE
@@ -93,6 +101,25 @@ standard input.
93
101
 
94
102
  ---
95
103
 
104
+ ## Interactive mode
105
+
106
+ Run it with no arguments and you get a menu instead of flags:
107
+
108
+ ```bash
109
+ decryptre
110
+ ```
111
+
112
+ Arrow keys (or `j`/`k`) move, `1`-`6` jump straight to an option, Enter
113
+ selects, `q` goes back and Ctrl+C quits. Choose **Decrypt / decode text**,
114
+ paste ciphertext or a file path, optionally give a passphrase, then pick from
115
+ the ranked results and ask for another layer if the text is still encoded.
116
+ Encrypt and identify work the same way.
117
+
118
+ `decryptre --help` still prints the full command reference, and when input is
119
+ piped (`cat cipher.txt | decryptre`) the help is printed instead of the menu.
120
+
121
+ ---
122
+
96
123
  ## Commands
97
124
 
98
125
  ### `decryptre decrypt`
@@ -4,7 +4,7 @@ Everything in this package runs locally. There are no network calls, no
4
4
  telemetry and no remote wordlists.
5
5
  """
6
6
 
7
- __version__ = "0.1.0"
7
+ __version__ = "0.2.0"
8
8
 
9
9
  from .models import Candidate # noqa: F401
10
10
 
@@ -365,7 +365,17 @@ def build_parser() -> argparse.ArgumentParser:
365
365
 
366
366
  def main(argv: Optional[List[str]] = None) -> int:
367
367
  parser = build_parser()
368
- args = parser.parse_args(argv)
368
+ arguments = list(sys.argv[1:] if argv is None else argv)
369
+ if not arguments:
370
+ # Bare `decryptre` opens the interactive menu; when input is piped or
371
+ # redirected there is nothing to navigate, so show the help instead.
372
+ if sys.stdin.isatty() and sys.stdout.isatty():
373
+ from .interactive import run
374
+
375
+ return run()
376
+ parser.print_help()
377
+ return 0
378
+ args = parser.parse_args(arguments)
369
379
  return args.func(args)
370
380
 
371
381
 
@@ -0,0 +1,427 @@
1
+ """Interactive terminal UI for DecryptRE.
2
+
3
+ Typing ``decryptre`` with no arguments starts this menu. Everything here uses
4
+ only the standard library, keeps working when stdout is redirected (it falls
5
+ back to a numbered prompt), and never touches the network.
6
+
7
+ Navigation: arrow keys or ``j``/``k`` move, ``1``-``9`` jump straight to that
8
+ item, Enter selects, ``q`` goes back, Ctrl+C quits.
9
+ """
10
+
11
+ import os
12
+ import sys
13
+ import textwrap
14
+ from typing import List, Optional, Sequence, Tuple
15
+
16
+ from . import __version__, classical, encodings, modern_crypto, xor
17
+ from .auto_detect import detect
18
+ from .cli import _xor_wrapper, load_wordlist, read_input
19
+ from .models import Candidate
20
+ from .scorer import score_text
21
+
22
+ BANNER = r"""
23
+ ____ _ ____ _____
24
+ | _ \ ___ ___ _ __ _ _ _ __| |_| _ \| ____|
25
+ | | | |/ _ \/ __| '__| | | | '__| __| |_) | _|
26
+ | |_| | __/ (__| | | |_| | | | |_| _ <| |___
27
+ |____/ \___|\___|_| \__, |_| \__|_| \_\_____|
28
+ |___/ offline text recovery
29
+ """
30
+
31
+ HINT = " up/down or j/k move · 1-6 jump · Enter select · q back · Ctrl+C quit"
32
+
33
+
34
+ # ---------------------------------------------------------------------------
35
+ # Terminal handling
36
+ # ---------------------------------------------------------------------------
37
+
38
+ def _is_tty() -> bool:
39
+ try:
40
+ return sys.stdin.isatty() and sys.stdout.isatty()
41
+ except (AttributeError, ValueError):
42
+ return False
43
+
44
+
45
+ def _enable_ansi() -> None:
46
+ """Turn on virtual-terminal escape codes on Windows 10+."""
47
+ if os.name != "nt":
48
+ return
49
+ try:
50
+ import ctypes
51
+
52
+ handle = ctypes.windll.kernel32.GetStdHandle(-11)
53
+ ctypes.windll.kernel32.SetConsoleMode(handle, 7)
54
+ except Exception:
55
+ pass
56
+
57
+
58
+ def _read_key() -> str:
59
+ """Read one keypress and return a name: up/down/enter/back/quit or a char."""
60
+ if os.name == "nt":
61
+ import msvcrt
62
+
63
+ ch = msvcrt.getwch()
64
+ if ch in ("\x00", "\xe0"):
65
+ code = msvcrt.getwch()
66
+ return {"H": "up", "P": "down", "K": "left", "M": "right"}.get(code, "")
67
+ if ch == "\r":
68
+ return "enter"
69
+ if ch == "\x03":
70
+ raise KeyboardInterrupt
71
+ if ch == "\x1b":
72
+ return "back"
73
+ return ch
74
+
75
+ import select
76
+ import termios
77
+ import tty
78
+
79
+ fd = sys.stdin.fileno()
80
+ old = termios.tcgetattr(fd)
81
+ try:
82
+ tty.setraw(fd)
83
+ # Read the file descriptor directly: the text wrapper buffers ahead,
84
+ # which would make select() miss bytes and break arrow-key decoding.
85
+ raw = os.read(fd, 1)
86
+ if raw == b"\x03":
87
+ raise KeyboardInterrupt
88
+ if raw == b"\x1b":
89
+ ready, _, _ = select.select([fd], [], [], 0.05)
90
+ if not ready:
91
+ return "back"
92
+ seq = os.read(fd, 2).decode("ascii", "ignore")
93
+ return {"[A": "up", "[B": "down", "[C": "right", "[D": "left"}.get(seq, "")
94
+ if raw in (b"\r", b"\n"):
95
+ return "enter"
96
+ finally:
97
+ termios.tcsetattr(fd, termios.TCSADRAIN, old)
98
+ return raw.decode("utf-8", "ignore")
99
+
100
+
101
+ def _menu_lines(title: str, options: Sequence[str], index: int) -> List[str]:
102
+ lines = [""]
103
+ if title:
104
+ lines.extend(f" {line}" for line in title.splitlines())
105
+ lines.append("")
106
+ for position, option in enumerate(options):
107
+ marker = "\u276f" if position == index else " "
108
+ lines.append(f" {marker} {position + 1}. {option}")
109
+ lines.append("")
110
+ lines.append(HINT)
111
+ return lines
112
+
113
+
114
+ def _fallback_menu(title: str, options: Sequence[str]) -> Optional[int]:
115
+ if title:
116
+ print(title)
117
+ for position, option in enumerate(options, start=1):
118
+ print(f" {position}. {option}")
119
+ while True:
120
+ try:
121
+ answer = input("Choose a number (blank to go back): ").strip()
122
+ except EOFError:
123
+ return None
124
+ if not answer:
125
+ return None
126
+ if answer.isdigit() and 1 <= int(answer) <= len(options):
127
+ return int(answer) - 1
128
+ print(" Please enter one of the numbers shown.")
129
+
130
+
131
+ def menu(title: str, options: Sequence[str]) -> Optional[int]:
132
+ """Show a menu and return the chosen index, or None to go back."""
133
+ if not _is_tty():
134
+ return _fallback_menu(title, options)
135
+
136
+ _enable_ansi()
137
+ index = 0
138
+ lines = _menu_lines(title, options, index)
139
+ sys.stdout.write("\033[?25l")
140
+ sys.stdout.write("\n".join(lines) + "\n")
141
+ sys.stdout.flush()
142
+ try:
143
+ while True:
144
+ key = _read_key()
145
+ moved = False
146
+ if key in ("up", "k"):
147
+ index = (index - 1) % len(options)
148
+ moved = True
149
+ elif key in ("down", "j"):
150
+ index = (index + 1) % len(options)
151
+ moved = True
152
+ elif key == "enter":
153
+ return index
154
+ elif key in ("back", "q"):
155
+ return None
156
+ elif len(key) == 1 and key.isdigit():
157
+ position = int(key) - 1
158
+ if 0 <= position < len(options):
159
+ return position
160
+ if moved:
161
+ sys.stdout.write(f"\033[{len(lines)}A")
162
+ lines = _menu_lines(title, options, index)
163
+ for line in lines:
164
+ sys.stdout.write("\r\033[2K" + line + "\n")
165
+ sys.stdout.flush()
166
+ finally:
167
+ sys.stdout.write("\033[?25h")
168
+ sys.stdout.flush()
169
+
170
+
171
+ def ask(prompt: str) -> str:
172
+ try:
173
+ return input(f" {prompt} ").strip()
174
+ except EOFError:
175
+ return ""
176
+
177
+
178
+ def pause() -> None:
179
+ if _is_tty():
180
+ ask("Press Enter to continue.")
181
+
182
+
183
+ def show(text: str) -> None:
184
+ width = max(40, min(100, (os.get_terminal_size().columns if _is_tty() else 90) - 6))
185
+ print()
186
+ for line in text.splitlines() or [""]:
187
+ for wrapped in textwrap.wrap(line, width=width) or [""]:
188
+ print(f" {wrapped}")
189
+ print()
190
+
191
+
192
+ # ---------------------------------------------------------------------------
193
+ # Actions
194
+ # ---------------------------------------------------------------------------
195
+
196
+ def _results_screen(results: List[Candidate]) -> None:
197
+ """Numbered result picker with arrow/number navigation."""
198
+ while True:
199
+ labels = []
200
+ for candidate in results:
201
+ params = candidate.describe_params()
202
+ preview = candidate.text.replace("\n", " ").strip()
203
+ if len(preview) > 58:
204
+ preview = preview[:55] + "..."
205
+ label = f"{preview} [{candidate.method} {params}]".rstrip()
206
+ labels.append(label)
207
+
208
+ choice = menu("Pick the result that looks right:", labels)
209
+ if choice is None:
210
+ return
211
+
212
+ candidate = results[choice]
213
+ print()
214
+ print(f" {candidate.method} {candidate.describe_params()}".rstrip())
215
+ show(candidate.text)
216
+
217
+ actions = [
218
+ "Try this result again (another layer)",
219
+ "Back to the list",
220
+ "Back to the main menu",
221
+ ]
222
+ action = menu("What next?", actions)
223
+ if action == 0:
224
+ results = _search(candidate.text, "", quiet=True)
225
+ if not results:
226
+ print(" Nothing further could be decoded from that.")
227
+ return
228
+ continue
229
+ if action == 1:
230
+ continue
231
+ return
232
+
233
+
234
+ def _search(text: str, key: str, quiet: bool = False) -> List[Candidate]:
235
+ """Decrypt ``text`` and return the best candidates."""
236
+ results: List[Candidate] = []
237
+ if key:
238
+ try:
239
+ plain = modern_crypto.decrypt_modern(text, key)
240
+ results.append(
241
+ Candidate(plain, "modern", {"alg": "key"}, score_text(plain))
242
+ )
243
+ except Exception:
244
+ pass
245
+
246
+ if not quiet:
247
+ print(" Searching offline (a few seconds for long text)...", flush=True)
248
+ found = detect(
249
+ text,
250
+ max_depth=3,
251
+ top=6,
252
+ wordlist=[] if key else load_wordlist(),
253
+ )
254
+ for candidate in found:
255
+ if all(candidate.text != existing.text for existing in results):
256
+ results.append(candidate)
257
+ results.sort(key=lambda c: c.score, reverse=True)
258
+ return results
259
+
260
+
261
+ def decrypt_flow() -> None:
262
+ print()
263
+ print(" Paste ciphertext, or type a file path. Multi-line input: use the CLI")
264
+ print(" with --input - and pipe the text in.")
265
+ text = ask("Ciphertext or file:")
266
+ if not text:
267
+ return
268
+ text = read_input(text)
269
+ key = ask("Passphrase, if you know it (blank to search):")
270
+
271
+ results = _search(text, key)
272
+ if not results:
273
+ print(" Nothing decoded. Try the CLI with --max-depth 4 or an explicit method.")
274
+ pause()
275
+ return
276
+ _results_screen(results)
277
+
278
+
279
+ ENCRYPT_METHODS: List[Tuple[str, str]] = [
280
+ ("Base64", "base64"),
281
+ ("Base32", "base32"),
282
+ ("Hex", "base16"),
283
+ ("Caesar / ROT-N", "caesar"),
284
+ ("Atbash", "atbash"),
285
+ ("Vigenere", "vigenere"),
286
+ ("Rail Fence", "railfence"),
287
+ ("XOR (passphrase)", "xor"),
288
+ ("AES (passphrase)", "aes"),
289
+ ("Fernet (passphrase)", "fernet"),
290
+ ]
291
+
292
+
293
+ def encrypt_flow() -> None:
294
+ labels = [label for label, _ in ENCRYPT_METHODS]
295
+ choice = menu("Encrypt or encode with which method?", labels)
296
+ if choice is None:
297
+ return
298
+ method = ENCRYPT_METHODS[choice][1]
299
+
300
+ text = ask("Text to encrypt:")
301
+ if not text:
302
+ return
303
+
304
+ try:
305
+ if method in encodings.ENCODINGS:
306
+ output = encodings.encode(text, method)
307
+ elif method == "caesar":
308
+ shift = ask("Shift (default 3):")
309
+ output = classical.caesar_encrypt(text, int(shift) if shift.isdigit() else 3)
310
+ elif method == "atbash":
311
+ output = classical.atbash(text)
312
+ elif method == "railfence":
313
+ rails = ask("Rails (default 4):")
314
+ output = classical.railfence_encrypt(text, int(rails) if rails.isdigit() else 4)
315
+ else:
316
+ key = ask("Passphrase:")
317
+ if not key:
318
+ print(" A passphrase is required for this method.")
319
+ pause()
320
+ return
321
+ if method == "vigenere":
322
+ output = classical.vigenere_encrypt(text, key)
323
+ elif method == "xor":
324
+ output = _xor_wrapper(xor.xor_encrypt(text, key))
325
+ elif method == "aes":
326
+ output = modern_crypto.encrypt_aes(text, key)
327
+ else:
328
+ output = modern_crypto.encrypt_fernet(text, key)
329
+ except (ValueError, TypeError) as exc:
330
+ print(f" Could not encrypt: {exc}")
331
+ pause()
332
+ return
333
+
334
+ print("\n Ciphertext:\n")
335
+ show(output)
336
+ pause()
337
+
338
+
339
+ def identify_flow() -> None:
340
+ text = ask("Hash or encoded string:")
341
+ if not text:
342
+ return
343
+ text = read_input(text).strip()
344
+ matches = modern_crypto.identify_hash(text)
345
+ print(f"\n input length: {len(text)}")
346
+ if matches:
347
+ for match in matches:
348
+ print(f" {match}")
349
+ else:
350
+ print(" no known encoding or hash shape detected")
351
+ print(" note: hashes are one-way; DecryptRE identifies them but cannot reverse them")
352
+ pause()
353
+
354
+
355
+ def help_screen() -> None:
356
+ print(
357
+ """
358
+ Command line equivalents
359
+
360
+ decryptre decrypt --input "TEXT" auto search
361
+ decryptre decrypt --input "TEXT" --method caesar
362
+ decryptre decrypt --input file.txt --method aes --key "pass"
363
+ decryptre decrypt --input "TEXT" --key "pass" --method fernet
364
+ decryptre encrypt --input "TEXT" --method aes --key "pass"
365
+ decryptre identify --input "5d41402abc4b2a76b9719d911017c592"
366
+ decryptre --help full reference
367
+
368
+ Tips
369
+
370
+ * --input takes text, a file path, or - to read stdin.
371
+ * Known passphrase containers: use --method fernet or --method aes.
372
+ Auto mode would run a 10,000-word list and take minutes.
373
+ * --top 10 shows more results; --max-depth 4 peels more layers.
374
+ * Everything runs offline: no accounts, no keys, no network.
375
+
376
+ Responsible use
377
+
378
+ Decrypt only data you own or have permission to test.
379
+ """
380
+ )
381
+ pause()
382
+
383
+
384
+ # ---------------------------------------------------------------------------
385
+ # Main loop
386
+ # ---------------------------------------------------------------------------
387
+
388
+ def run() -> int:
389
+ _enable_ansi()
390
+ print(BANNER)
391
+ print(f" v{__version__} · everything runs offline")
392
+ options = [
393
+ "Decrypt / decode text",
394
+ "Encrypt text",
395
+ "Identify a hash or encoding",
396
+ "Help and examples",
397
+ "Quit",
398
+ ]
399
+ while True:
400
+ choice = menu("", options)
401
+ if choice is None or choice == 4:
402
+ print("\n bye\n")
403
+ return 0
404
+ try:
405
+ if choice == 0:
406
+ decrypt_flow()
407
+ elif choice == 1:
408
+ encrypt_flow()
409
+ elif choice == 2:
410
+ identify_flow()
411
+ else:
412
+ help_screen()
413
+ except KeyboardInterrupt:
414
+ print("\n interrupted\n")
415
+ return 130
416
+
417
+
418
+ def main() -> int:
419
+ try:
420
+ return run()
421
+ except KeyboardInterrupt:
422
+ print("\n interrupted\n")
423
+ return 130
424
+
425
+
426
+ if __name__ == "__main__":
427
+ raise SystemExit(main())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: decryptre
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Offline, open-source CLI that decrypts text with or without a passphrase and re-encrypts it with the same methods.
5
5
  Author: Jason Marvello
6
6
  License-Expression: MIT
@@ -74,6 +74,14 @@ Two honest statements that the code and docs repeat:
74
74
 
75
75
  Requirements: **Python 3.9 or newer**.
76
76
 
77
+ The quickest way is from PyPI:
78
+
79
+ ```bash
80
+ pip install decryptre
81
+ ```
82
+
83
+ Or install from source:
84
+
77
85
  ```bash
78
86
  git clone https://github.com/JasonMarvello/DecryptRE.git
79
87
  cd DecryptRE
@@ -115,6 +123,25 @@ standard input.
115
123
 
116
124
  ---
117
125
 
126
+ ## Interactive mode
127
+
128
+ Run it with no arguments and you get a menu instead of flags:
129
+
130
+ ```bash
131
+ decryptre
132
+ ```
133
+
134
+ Arrow keys (or `j`/`k`) move, `1`-`6` jump straight to an option, Enter
135
+ selects, `q` goes back and Ctrl+C quits. Choose **Decrypt / decode text**,
136
+ paste ciphertext or a file path, optionally give a passphrase, then pick from
137
+ the ranked results and ask for another layer if the text is still encoded.
138
+ Encrypt and identify work the same way.
139
+
140
+ `decryptre --help` still prints the full command reference, and when input is
141
+ piped (`cat cipher.txt | decryptre`) the help is printed instead of the menu.
142
+
143
+ ---
144
+
118
145
  ## Commands
119
146
 
120
147
  ### `decryptre decrypt`
@@ -8,6 +8,7 @@ decryptre/classical.py
8
8
  decryptre/cli.py
9
9
  decryptre/containers.py
10
10
  decryptre/encodings.py
11
+ decryptre/interactive.py
11
12
  decryptre/models.py
12
13
  decryptre/modern_crypto.py
13
14
  decryptre/ngrams.py
@@ -27,6 +28,7 @@ tests/test_auto_detect.py
27
28
  tests/test_classical.py
28
29
  tests/test_cli.py
29
30
  tests/test_encodings.py
31
+ tests/test_interactive.py
30
32
  tests/test_modern_crypto.py
31
33
  tests/test_offline.py
32
34
  tests/test_scorer.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "decryptre"
7
- version = "0.1.0"
7
+ version = "0.2.0"
8
8
  description = "Offline, open-source CLI that decrypts text with or without a passphrase and re-encrypts it with the same methods."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -0,0 +1,28 @@
1
+ import builtins
2
+
3
+ from decryptre import interactive
4
+ from decryptre.cli import main
5
+
6
+
7
+ def test_bare_command_prints_help_when_input_is_not_a_terminal(capsys):
8
+ assert main([]) == 0
9
+ assert "usage: decryptre" in capsys.readouterr().out
10
+
11
+
12
+ def test_menu_falls_back_to_numbers_without_a_terminal(monkeypatch):
13
+ monkeypatch.setattr(interactive, "_is_tty", lambda: False)
14
+ monkeypatch.setattr(builtins, "input", lambda prompt="": "2")
15
+ assert interactive.menu("Pick:", ["a", "b", "c"]) == 1
16
+
17
+
18
+ def test_menu_blank_answer_goes_back(monkeypatch):
19
+ monkeypatch.setattr(interactive, "_is_tty", lambda: False)
20
+ monkeypatch.setattr(builtins, "input", lambda prompt="": "")
21
+ assert interactive.menu("Pick:", ["a", "b"]) is None
22
+
23
+
24
+ def test_menu_reprompts_on_bad_input(monkeypatch):
25
+ monkeypatch.setattr(interactive, "_is_tty", lambda: False)
26
+ answers = iter(["9", "x", "1"])
27
+ monkeypatch.setattr(builtins, "input", lambda prompt="": next(answers))
28
+ assert interactive.menu("Pick:", ["a", "b"]) == 0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes