decodify 0.1.3__tar.gz → 0.1.4__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.
- decodify-0.1.4/PKG-INFO +140 -0
- decodify-0.1.4/README.md +108 -0
- decodify-0.1.4/decodify/__init__.py +17 -0
- decodify-0.1.4/decodify/algorithms/__init__.py +72 -0
- decodify-0.1.4/decodify/algorithms/affine.py +59 -0
- decodify-0.1.4/decodify/algorithms/atbash.py +31 -0
- decodify-0.1.4/decodify/algorithms/baconian.py +42 -0
- decodify-0.1.4/decodify/algorithms/base32.py +37 -0
- decodify-0.1.4/decodify/algorithms/base36.py +37 -0
- decodify-0.1.4/decodify/algorithms/base45.py +75 -0
- decodify-0.1.4/decodify/algorithms/base58.py +58 -0
- decodify-0.1.4/decodify/algorithms/base64.py +41 -0
- decodify-0.1.4/decodify/algorithms/base85.py +51 -0
- decodify-0.1.4/decodify/algorithms/binary.py +32 -0
- decodify-0.1.4/decodify/algorithms/brainfuck.py +79 -0
- decodify-0.1.4/decodify/algorithms/caesar.py +38 -0
- decodify-0.1.4/decodify/algorithms/hex.py +30 -0
- decodify-0.1.4/decodify/algorithms/html_entities.py +21 -0
- decodify-0.1.4/decodify/algorithms/jwt.py +50 -0
- decodify-0.1.4/decodify/algorithms/morse.py +70 -0
- decodify-0.1.4/decodify/algorithms/nato.py +47 -0
- decodify-0.1.4/decodify/algorithms/polybius.py +54 -0
- decodify-0.1.4/decodify/algorithms/punycode.py +29 -0
- decodify-0.1.4/decodify/algorithms/quoted_printable.py +21 -0
- decodify-0.1.4/decodify/algorithms/rail_fence.py +50 -0
- decodify-0.1.4/decodify/algorithms/rot13.py +20 -0
- decodify-0.1.4/decodify/algorithms/rot47.py +24 -0
- decodify-0.1.4/decodify/algorithms/tap_code.py +67 -0
- decodify-0.1.4/decodify/algorithms/unicode_escape.py +29 -0
- {decodify-0.1.3 → decodify-0.1.4}/decodify/algorithms/url.py +8 -2
- decodify-0.1.4/decodify/algorithms/uuencode.py +43 -0
- decodify-0.1.4/decodify/algorithms/vigenere.py +50 -0
- decodify-0.1.4/decodify/algorithms/xor_cipher.py +26 -0
- decodify-0.1.4/decodify/cli.py +81 -0
- decodify-0.1.4/decodify/decodify.py +156 -0
- decodify-0.1.4/decodify.egg-info/PKG-INFO +140 -0
- decodify-0.1.4/decodify.egg-info/SOURCES.txt +41 -0
- decodify-0.1.4/setup.py +41 -0
- decodify-0.1.4/tests/test_decodify.py +354 -0
- decodify-0.1.3/PKG-INFO +0 -183
- decodify-0.1.3/README.md +0 -154
- decodify-0.1.3/decodify/__init__.py +0 -6
- decodify-0.1.3/decodify/algorithms/__init__.py +0 -6
- decodify-0.1.3/decodify/algorithms/base64.py +0 -18
- decodify-0.1.3/decodify/algorithms/binary.py +0 -23
- decodify-0.1.3/decodify/algorithms/hex.py +0 -15
- decodify-0.1.3/decodify/algorithms/morse.py +0 -29
- decodify-0.1.3/decodify/cli.py +0 -47
- decodify-0.1.3/decodify/decodify.py +0 -78
- decodify-0.1.3/decodify.egg-info/PKG-INFO +0 -183
- decodify-0.1.3/decodify.egg-info/SOURCES.txt +0 -16
- decodify-0.1.3/setup.py +0 -34
- {decodify-0.1.3 → decodify-0.1.4}/decodify.egg-info/dependency_links.txt +0 -0
- {decodify-0.1.3 → decodify-0.1.4}/decodify.egg-info/entry_points.txt +0 -0
- {decodify-0.1.3 → decodify-0.1.4}/decodify.egg-info/top_level.txt +0 -0
- {decodify-0.1.3 → decodify-0.1.4}/setup.cfg +0 -0
decodify-0.1.4/PKG-INFO
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: decodify
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: Detect and decode (or encode) messages with 29 classic and modern encodings/ciphers.
|
|
5
|
+
Home-page: https://github.com/ishanoshada/decodify
|
|
6
|
+
Author: Ishan Oshada
|
|
7
|
+
Author-email: ishan.kodithuwakku.official@gmail.com
|
|
8
|
+
Keywords: encoding,decoding,cryptography,cipher,decode,encoder,decoder,base64,morse,caesar,vigenere,jwt,base58
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Security :: Cryptography
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Intended Audience :: Developers
|
|
20
|
+
Classifier: Development Status :: 4 - Beta
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
Dynamic: author
|
|
24
|
+
Dynamic: author-email
|
|
25
|
+
Dynamic: classifier
|
|
26
|
+
Dynamic: description
|
|
27
|
+
Dynamic: description-content-type
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: keywords
|
|
30
|
+
Dynamic: requires-python
|
|
31
|
+
Dynamic: summary
|
|
32
|
+
|
|
33
|
+
# Decodify
|
|
34
|
+
|
|
35
|
+
**Decodify** is a Python package that detects and decodes (or encodes) messages using **29 classic and modern** encodings and ciphers. It provides both a simple Python API and a command-line interface.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
- **29 algorithms** covering base encodings, web/text encodings, classical ciphers, and historical specialty codes
|
|
42
|
+
- **Automatic detection** with priority for distinctive formats
|
|
43
|
+
- **Encode + decode** round-trip support for every algorithm
|
|
44
|
+
- **Keyed ciphers** (Caesar, Vigenère, XOR, Affine, Rail Fence) accept keys/shifts via API or CLI
|
|
45
|
+
- **CLI** with file I/O, algorithm forcing, and encoding mode
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Supported Algorithms
|
|
50
|
+
|
|
51
|
+
| Category | Algorithms |
|
|
52
|
+
|----------|------------|
|
|
53
|
+
| **Base encodings** | `base64`, `base32`, `base58`, `base85` (Ascii85), `base45` (RFC 9285), `base36`, `hex`, `binary` |
|
|
54
|
+
| **Text / web** | `url`, `quoted_printable`, `html_entities`, `unicode_escape`, `punycode`, `jwt` (header+payload) |
|
|
55
|
+
| **Classical ciphers** | `rot13`, `rot47`, `caesar`, `atbash`, `vigenere`, `rail_fence`, `affine`, `xor` |
|
|
56
|
+
| **Historical / specialty** | `morse`, `baconian`, `polybius`, `tap_code`, `nato`, `uuencode`, `brainfuck` |
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install -e .
|
|
64
|
+
# or
|
|
65
|
+
pip install decodify
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Quick Start (Python)
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from decodify import decode_message, encode_message, list_algorithms
|
|
74
|
+
|
|
75
|
+
# Auto-detect + decode
|
|
76
|
+
text, probs = decode_message("SGVsbG8=")
|
|
77
|
+
print(text) # Hello
|
|
78
|
+
print(probs) # {'base64': 1.0, ...}
|
|
79
|
+
|
|
80
|
+
# Force algorithm
|
|
81
|
+
text, _ = decode_message("Uryyb", algorithm="rot13")
|
|
82
|
+
text, _ = decode_message("...", algorithm="vigenere", key="LEMON")
|
|
83
|
+
text, _ = decode_message("...", algorithm="caesar", shift=13)
|
|
84
|
+
|
|
85
|
+
# Encode
|
|
86
|
+
print(encode_message("Hello World", "base64"))
|
|
87
|
+
print(encode_message("SOS", "nato"))
|
|
88
|
+
print(encode_message("Attack at dawn", "caesar", shift=4))
|
|
89
|
+
print(encode_message("secret", "xor", key="key"))
|
|
90
|
+
|
|
91
|
+
print(list_algorithms())
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## CLI
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Auto-detect
|
|
100
|
+
decodify "SGVsbG8="
|
|
101
|
+
|
|
102
|
+
# Force algorithm
|
|
103
|
+
decodify -a base64 "SGVsbG8="
|
|
104
|
+
decodify -a morse ".... . .-.. .-.. ---"
|
|
105
|
+
decodify -a caesar --shift 13 "Uryyb"
|
|
106
|
+
decodify -a vigenere --key SECRET "ciphertext"
|
|
107
|
+
|
|
108
|
+
# Encode
|
|
109
|
+
decodify -e -a base64 "Hello World"
|
|
110
|
+
decodify -e -a nato "HELP"
|
|
111
|
+
|
|
112
|
+
# Files
|
|
113
|
+
decodify -f encoded.txt -o decoded.txt
|
|
114
|
+
|
|
115
|
+
# List all algorithms
|
|
116
|
+
decodify --list
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Notes on detection
|
|
122
|
+
|
|
123
|
+
Detection is heuristic. Distinctive formats (JWT, uuencode, Brainfuck, Tap code, Morse, NATO, Baconian, Polybius, Base45/58/85, etc.) are preferred. Ambiguous classical ciphers (Caesar, Vigenère, ROT, XOR, Affine, Rail Fence) are **not** auto-detected — pass `-a` / `algorithm=` explicitly together with the key/shift when needed.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|
|
130
|
+
|
|
131
|
+
## Contributing
|
|
132
|
+
|
|
133
|
+
Contributions welcome — add new algorithms under `decodify/algorithms/` following the `is_X` / `decode_X` / `encode_X` pattern and register them in `algorithms/__init__.py`.
|
|
134
|
+
|
|
135
|
+
## Contact / Original author
|
|
136
|
+
|
|
137
|
+
- GitHub: [ishanoshada](https://github.com/ishanoshada)
|
|
138
|
+
- Repository: https://github.com/ishanoshada/decodify
|
|
139
|
+
|
|
140
|
+
Enjoy decoding with **Decodify**! 🚀
|
decodify-0.1.4/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Decodify
|
|
2
|
+
|
|
3
|
+
**Decodify** is a Python package that detects and decodes (or encodes) messages using **29 classic and modern** encodings and ciphers. It provides both a simple Python API and a command-line interface.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **29 algorithms** covering base encodings, web/text encodings, classical ciphers, and historical specialty codes
|
|
10
|
+
- **Automatic detection** with priority for distinctive formats
|
|
11
|
+
- **Encode + decode** round-trip support for every algorithm
|
|
12
|
+
- **Keyed ciphers** (Caesar, Vigenère, XOR, Affine, Rail Fence) accept keys/shifts via API or CLI
|
|
13
|
+
- **CLI** with file I/O, algorithm forcing, and encoding mode
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Supported Algorithms
|
|
18
|
+
|
|
19
|
+
| Category | Algorithms |
|
|
20
|
+
|----------|------------|
|
|
21
|
+
| **Base encodings** | `base64`, `base32`, `base58`, `base85` (Ascii85), `base45` (RFC 9285), `base36`, `hex`, `binary` |
|
|
22
|
+
| **Text / web** | `url`, `quoted_printable`, `html_entities`, `unicode_escape`, `punycode`, `jwt` (header+payload) |
|
|
23
|
+
| **Classical ciphers** | `rot13`, `rot47`, `caesar`, `atbash`, `vigenere`, `rail_fence`, `affine`, `xor` |
|
|
24
|
+
| **Historical / specialty** | `morse`, `baconian`, `polybius`, `tap_code`, `nato`, `uuencode`, `brainfuck` |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install -e .
|
|
32
|
+
# or
|
|
33
|
+
pip install decodify
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Quick Start (Python)
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from decodify import decode_message, encode_message, list_algorithms
|
|
42
|
+
|
|
43
|
+
# Auto-detect + decode
|
|
44
|
+
text, probs = decode_message("SGVsbG8=")
|
|
45
|
+
print(text) # Hello
|
|
46
|
+
print(probs) # {'base64': 1.0, ...}
|
|
47
|
+
|
|
48
|
+
# Force algorithm
|
|
49
|
+
text, _ = decode_message("Uryyb", algorithm="rot13")
|
|
50
|
+
text, _ = decode_message("...", algorithm="vigenere", key="LEMON")
|
|
51
|
+
text, _ = decode_message("...", algorithm="caesar", shift=13)
|
|
52
|
+
|
|
53
|
+
# Encode
|
|
54
|
+
print(encode_message("Hello World", "base64"))
|
|
55
|
+
print(encode_message("SOS", "nato"))
|
|
56
|
+
print(encode_message("Attack at dawn", "caesar", shift=4))
|
|
57
|
+
print(encode_message("secret", "xor", key="key"))
|
|
58
|
+
|
|
59
|
+
print(list_algorithms())
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## CLI
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Auto-detect
|
|
68
|
+
decodify "SGVsbG8="
|
|
69
|
+
|
|
70
|
+
# Force algorithm
|
|
71
|
+
decodify -a base64 "SGVsbG8="
|
|
72
|
+
decodify -a morse ".... . .-.. .-.. ---"
|
|
73
|
+
decodify -a caesar --shift 13 "Uryyb"
|
|
74
|
+
decodify -a vigenere --key SECRET "ciphertext"
|
|
75
|
+
|
|
76
|
+
# Encode
|
|
77
|
+
decodify -e -a base64 "Hello World"
|
|
78
|
+
decodify -e -a nato "HELP"
|
|
79
|
+
|
|
80
|
+
# Files
|
|
81
|
+
decodify -f encoded.txt -o decoded.txt
|
|
82
|
+
|
|
83
|
+
# List all algorithms
|
|
84
|
+
decodify --list
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Notes on detection
|
|
90
|
+
|
|
91
|
+
Detection is heuristic. Distinctive formats (JWT, uuencode, Brainfuck, Tap code, Morse, NATO, Baconian, Polybius, Base45/58/85, etc.) are preferred. Ambiguous classical ciphers (Caesar, Vigenère, ROT, XOR, Affine, Rail Fence) are **not** auto-detected — pass `-a` / `algorithm=` explicitly together with the key/shift when needed.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT
|
|
98
|
+
|
|
99
|
+
## Contributing
|
|
100
|
+
|
|
101
|
+
Contributions welcome — add new algorithms under `decodify/algorithms/` following the `is_X` / `decode_X` / `encode_X` pattern and register them in `algorithms/__init__.py`.
|
|
102
|
+
|
|
103
|
+
## Contact / Original author
|
|
104
|
+
|
|
105
|
+
- GitHub: [ishanoshada](https://github.com/ishanoshada)
|
|
106
|
+
- Repository: https://github.com/ishanoshada/decodify
|
|
107
|
+
|
|
108
|
+
Enjoy decoding with **Decodify**! 🚀
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# decodify/__init__.py
|
|
2
|
+
from .decodify import Decodify
|
|
3
|
+
|
|
4
|
+
# Expose the main class and convenience functions
|
|
5
|
+
detect_algorithm = Decodify.detect_algorithm
|
|
6
|
+
decode_message = Decodify.decode_message
|
|
7
|
+
encode_message = Decodify.encode_message
|
|
8
|
+
list_algorithms = Decodify.list_algorithms
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1.4"
|
|
11
|
+
__all__ = [
|
|
12
|
+
"Decodify",
|
|
13
|
+
"detect_algorithm",
|
|
14
|
+
"decode_message",
|
|
15
|
+
"encode_message",
|
|
16
|
+
"list_algorithms",
|
|
17
|
+
]
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# decodify/algorithms/__init__.py
|
|
2
|
+
from .base64 import is_base64, decode_base64, encode_base64
|
|
3
|
+
from .hex import is_hex, decode_hex, encode_hex
|
|
4
|
+
from .url import is_url_encoded, decode_url, encode_url
|
|
5
|
+
from .binary import is_binary, decode_binary, encode_binary
|
|
6
|
+
from .morse import is_morse, decode_morse, encode_morse
|
|
7
|
+
from .base32 import is_base32, decode_base32, encode_base32
|
|
8
|
+
from .base58 import is_base58, decode_base58, encode_base58
|
|
9
|
+
from .base85 import is_base85, decode_base85, encode_base85
|
|
10
|
+
from .base45 import is_base45, decode_base45, encode_base45
|
|
11
|
+
from .base36 import is_base36, decode_base36, encode_base36
|
|
12
|
+
from .rot13 import is_rot13, decode_rot13, encode_rot13
|
|
13
|
+
from .rot47 import is_rot47, decode_rot47, encode_rot47
|
|
14
|
+
from .caesar import is_caesar, decode_caesar, encode_caesar, brute_force_caesar
|
|
15
|
+
from .atbash import is_atbash, decode_atbash, encode_atbash
|
|
16
|
+
from .vigenere import is_vigenere, decode_vigenere, encode_vigenere
|
|
17
|
+
from .rail_fence import is_rail_fence, decode_rail_fence, encode_rail_fence
|
|
18
|
+
from .xor_cipher import is_xor_cipher, decode_xor, encode_xor
|
|
19
|
+
from .baconian import is_baconian, decode_baconian, encode_baconian
|
|
20
|
+
from .polybius import is_polybius, decode_polybius, encode_polybius
|
|
21
|
+
from .affine import is_affine, decode_affine, encode_affine
|
|
22
|
+
from .tap_code import is_tap_code, decode_tap_code, encode_tap_code
|
|
23
|
+
from .nato import is_nato, decode_nato, encode_nato
|
|
24
|
+
from .quoted_printable import is_quoted_printable, decode_quoted_printable, encode_quoted_printable
|
|
25
|
+
from .html_entities import is_html_entities, decode_html_entities, encode_html_entities
|
|
26
|
+
from .unicode_escape import is_unicode_escape, decode_unicode_escape, encode_unicode_escape
|
|
27
|
+
from .uuencode import is_uuencode, decode_uuencode, encode_uuencode
|
|
28
|
+
from .punycode import is_punycode, decode_punycode, encode_punycode
|
|
29
|
+
from .jwt import is_jwt, decode_jwt, encode_jwt
|
|
30
|
+
from .brainfuck import is_brainfuck, decode_brainfuck, encode_brainfuck
|
|
31
|
+
|
|
32
|
+
# Registry for easy iteration
|
|
33
|
+
ALGORITHMS = {
|
|
34
|
+
"base64": (is_base64, decode_base64, encode_base64),
|
|
35
|
+
"hex": (is_hex, decode_hex, encode_hex),
|
|
36
|
+
"url": (is_url_encoded, decode_url, encode_url),
|
|
37
|
+
"binary": (is_binary, decode_binary, encode_binary),
|
|
38
|
+
"morse": (is_morse, decode_morse, encode_morse),
|
|
39
|
+
"base32": (is_base32, decode_base32, encode_base32),
|
|
40
|
+
"base58": (is_base58, decode_base58, encode_base58),
|
|
41
|
+
"base85": (is_base85, decode_base85, encode_base85),
|
|
42
|
+
"base45": (is_base45, decode_base45, encode_base45),
|
|
43
|
+
"base36": (is_base36, decode_base36, encode_base36),
|
|
44
|
+
"rot13": (is_rot13, decode_rot13, encode_rot13),
|
|
45
|
+
"rot47": (is_rot47, decode_rot47, encode_rot47),
|
|
46
|
+
"caesar": (is_caesar, decode_caesar, encode_caesar),
|
|
47
|
+
"atbash": (is_atbash, decode_atbash, encode_atbash),
|
|
48
|
+
"vigenere": (is_vigenere, decode_vigenere, encode_vigenere),
|
|
49
|
+
"rail_fence": (is_rail_fence, decode_rail_fence, encode_rail_fence),
|
|
50
|
+
"xor": (is_xor_cipher, decode_xor, encode_xor),
|
|
51
|
+
"baconian": (is_baconian, decode_baconian, encode_baconian),
|
|
52
|
+
"polybius": (is_polybius, decode_polybius, encode_polybius),
|
|
53
|
+
"affine": (is_affine, decode_affine, encode_affine),
|
|
54
|
+
"tap_code": (is_tap_code, decode_tap_code, encode_tap_code),
|
|
55
|
+
"nato": (is_nato, decode_nato, encode_nato),
|
|
56
|
+
"quoted_printable": (is_quoted_printable, decode_quoted_printable, encode_quoted_printable),
|
|
57
|
+
"html_entities": (is_html_entities, decode_html_entities, encode_html_entities),
|
|
58
|
+
"unicode_escape": (is_unicode_escape, decode_unicode_escape, encode_unicode_escape),
|
|
59
|
+
"uuencode": (is_uuencode, decode_uuencode, encode_uuencode),
|
|
60
|
+
"punycode": (is_punycode, decode_punycode, encode_punycode),
|
|
61
|
+
"jwt": (is_jwt, decode_jwt, encode_jwt),
|
|
62
|
+
"brainfuck": (is_brainfuck, decode_brainfuck, encode_brainfuck),
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
__all__ = list(ALGORITHMS.keys()) + [
|
|
66
|
+
"is_base64", "decode_base64", "encode_base64",
|
|
67
|
+
"is_hex", "decode_hex", "encode_hex",
|
|
68
|
+
"is_url_encoded", "decode_url", "encode_url",
|
|
69
|
+
"is_binary", "decode_binary", "encode_binary",
|
|
70
|
+
"is_morse", "decode_morse", "encode_morse",
|
|
71
|
+
"ALGORITHMS",
|
|
72
|
+
]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# decodify/algorithms/affine.py
|
|
2
|
+
def _modinv(a: int, m: int = 26) -> int:
|
|
3
|
+
for x in range(1, m):
|
|
4
|
+
if (a * x) % m == 1:
|
|
5
|
+
return x
|
|
6
|
+
raise ValueError("No modular inverse")
|
|
7
|
+
|
|
8
|
+
def is_affine(encoded: str) -> bool:
|
|
9
|
+
"""Weak cipher – detection disabled; user must specify algorithm."""
|
|
10
|
+
return False
|
|
11
|
+
# original logic kept below for reference
|
|
12
|
+
"""
|
|
13
|
+
Weak detection.
|
|
14
|
+
"""
|
|
15
|
+
if not encoded.strip():
|
|
16
|
+
return False
|
|
17
|
+
letters = sum(1 for c in encoded if c.isalpha())
|
|
18
|
+
return letters / max(len(encoded), 1) > 0.5
|
|
19
|
+
|
|
20
|
+
def decode_affine(encoded: str, a: int = 5, b: int = 8) -> str:
|
|
21
|
+
"""
|
|
22
|
+
Decode Affine cipher (ax + b mod 26). Default a=5, b=8.
|
|
23
|
+
a must be coprime with 26.
|
|
24
|
+
"""
|
|
25
|
+
try:
|
|
26
|
+
inv = _modinv(a)
|
|
27
|
+
except ValueError:
|
|
28
|
+
return encoded
|
|
29
|
+
result = []
|
|
30
|
+
for c in encoded:
|
|
31
|
+
if c.isupper():
|
|
32
|
+
y = ord(c) - ord('A')
|
|
33
|
+
x = (inv * (y - b)) % 26
|
|
34
|
+
result.append(chr(x + ord('A')))
|
|
35
|
+
elif c.islower():
|
|
36
|
+
y = ord(c) - ord('a')
|
|
37
|
+
x = (inv * (y - b)) % 26
|
|
38
|
+
result.append(chr(x + ord('a')))
|
|
39
|
+
else:
|
|
40
|
+
result.append(c)
|
|
41
|
+
return "".join(result)
|
|
42
|
+
|
|
43
|
+
def encode_affine(message: str, a: int = 5, b: int = 8) -> str:
|
|
44
|
+
"""
|
|
45
|
+
Encode with Affine cipher.
|
|
46
|
+
"""
|
|
47
|
+
result = []
|
|
48
|
+
for c in message:
|
|
49
|
+
if c.isupper():
|
|
50
|
+
x = ord(c) - ord('A')
|
|
51
|
+
y = (a * x + b) % 26
|
|
52
|
+
result.append(chr(y + ord('A')))
|
|
53
|
+
elif c.islower():
|
|
54
|
+
x = ord(c) - ord('a')
|
|
55
|
+
y = (a * x + b) % 26
|
|
56
|
+
result.append(chr(y + ord('a')))
|
|
57
|
+
else:
|
|
58
|
+
result.append(c)
|
|
59
|
+
return "".join(result)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# decodify/algorithms/atbash.py
|
|
2
|
+
def _atbash_char(c: str) -> str:
|
|
3
|
+
if c.isupper():
|
|
4
|
+
return chr(ord('Z') - (ord(c) - ord('A')))
|
|
5
|
+
if c.islower():
|
|
6
|
+
return chr(ord('z') - (ord(c) - ord('a')))
|
|
7
|
+
return c
|
|
8
|
+
|
|
9
|
+
def is_atbash(encoded: str) -> bool:
|
|
10
|
+
"""Weak cipher – detection disabled; user must specify algorithm."""
|
|
11
|
+
return False
|
|
12
|
+
# original logic kept below for reference
|
|
13
|
+
"""
|
|
14
|
+
Weak detection based on letter density.
|
|
15
|
+
"""
|
|
16
|
+
if not encoded.strip():
|
|
17
|
+
return False
|
|
18
|
+
letters = sum(1 for c in encoded if c.isalpha())
|
|
19
|
+
return letters / max(len(encoded), 1) > 0.5
|
|
20
|
+
|
|
21
|
+
def decode_atbash(encoded: str) -> str:
|
|
22
|
+
"""
|
|
23
|
+
Decode Atbash (same as encode).
|
|
24
|
+
"""
|
|
25
|
+
return "".join(_atbash_char(c) for c in encoded)
|
|
26
|
+
|
|
27
|
+
def encode_atbash(message: str) -> str:
|
|
28
|
+
"""
|
|
29
|
+
Encode with Atbash.
|
|
30
|
+
"""
|
|
31
|
+
return decode_atbash(message)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# decodify/algorithms/baconian.py
|
|
2
|
+
# 24-letter Baconian (I/J and U/V combined)
|
|
3
|
+
_BACON = {
|
|
4
|
+
"AAAAA": "A", "AAAAB": "B", "AAABA": "C", "AAABB": "D", "AABAA": "E",
|
|
5
|
+
"AABAB": "F", "AABBA": "G", "AABBB": "H", "ABAAA": "I", "ABAAB": "K",
|
|
6
|
+
"ABABA": "L", "ABABB": "M", "ABBAA": "N", "ABBAB": "O", "ABBBA": "P",
|
|
7
|
+
"ABBBB": "Q", "BAAAA": "R", "BAAAB": "S", "BAABA": "T", "BAABB": "U",
|
|
8
|
+
"BABAA": "W", "BABAB": "X", "BABBA": "Y", "BABBB": "Z",
|
|
9
|
+
}
|
|
10
|
+
_CHAR_TO_BACON = {v: k for k, v in _BACON.items()}
|
|
11
|
+
_CHAR_TO_BACON["J"] = "ABAAA" # same as I
|
|
12
|
+
_CHAR_TO_BACON["V"] = "BAABB" # same as U
|
|
13
|
+
|
|
14
|
+
def is_baconian(encoded: str) -> bool:
|
|
15
|
+
"""
|
|
16
|
+
Check for groups of 5 A/B characters.
|
|
17
|
+
"""
|
|
18
|
+
cleaned = encoded.strip().upper().replace(" ", "")
|
|
19
|
+
if not cleaned or len(cleaned) % 5 != 0:
|
|
20
|
+
return False
|
|
21
|
+
return all(c in "AB" for c in cleaned)
|
|
22
|
+
|
|
23
|
+
def decode_baconian(encoded: str) -> str:
|
|
24
|
+
"""
|
|
25
|
+
Decode Baconian cipher (A/B groups of 5).
|
|
26
|
+
"""
|
|
27
|
+
cleaned = encoded.strip().upper().replace(" ", "")
|
|
28
|
+
result = []
|
|
29
|
+
for i in range(0, len(cleaned), 5):
|
|
30
|
+
group = cleaned[i:i+5]
|
|
31
|
+
result.append(_BACON.get(group, "?"))
|
|
32
|
+
return "".join(result)
|
|
33
|
+
|
|
34
|
+
def encode_baconian(message: str) -> str:
|
|
35
|
+
"""
|
|
36
|
+
Encode to Baconian cipher.
|
|
37
|
+
"""
|
|
38
|
+
groups = []
|
|
39
|
+
for c in message.upper():
|
|
40
|
+
if c in _CHAR_TO_BACON:
|
|
41
|
+
groups.append(_CHAR_TO_BACON[c])
|
|
42
|
+
return " ".join(groups)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# decodify/algorithms/base32.py
|
|
2
|
+
import base64
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
def is_base32(encoded: str) -> bool:
|
|
6
|
+
"""
|
|
7
|
+
Check if the input is a valid Base32 encoded string.
|
|
8
|
+
"""
|
|
9
|
+
cleaned = encoded.strip().upper().replace(" ", "")
|
|
10
|
+
if not cleaned or len(cleaned) % 8 not in (0, 2, 4, 5, 7): # with padding
|
|
11
|
+
# allow without strict padding check
|
|
12
|
+
pass
|
|
13
|
+
pattern = re.compile(r"^[A-Z2-7=]+$")
|
|
14
|
+
if not pattern.match(cleaned):
|
|
15
|
+
return False
|
|
16
|
+
try:
|
|
17
|
+
base64.b32decode(cleaned, casefold=True)
|
|
18
|
+
return True
|
|
19
|
+
except Exception:
|
|
20
|
+
return False
|
|
21
|
+
|
|
22
|
+
def decode_base32(encoded: str) -> str:
|
|
23
|
+
"""
|
|
24
|
+
Decode a Base32 encoded string.
|
|
25
|
+
"""
|
|
26
|
+
cleaned = encoded.strip().upper().replace(" ", "")
|
|
27
|
+
# fix padding
|
|
28
|
+
pad = 8 - (len(cleaned) % 8)
|
|
29
|
+
if pad != 8:
|
|
30
|
+
cleaned += "=" * pad
|
|
31
|
+
return base64.b32decode(cleaned).decode("utf-8")
|
|
32
|
+
|
|
33
|
+
def encode_base32(message: str) -> str:
|
|
34
|
+
"""
|
|
35
|
+
Encode a string to Base32.
|
|
36
|
+
"""
|
|
37
|
+
return base64.b32encode(message.encode("utf-8")).decode("ascii")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# decodify/algorithms/base36.py
|
|
2
|
+
_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
3
|
+
|
|
4
|
+
def is_base36(encoded: str) -> bool:
|
|
5
|
+
"""
|
|
6
|
+
Check if the input is a valid Base36 string.
|
|
7
|
+
"""
|
|
8
|
+
cleaned = encoded.strip().lower()
|
|
9
|
+
if not cleaned:
|
|
10
|
+
return False
|
|
11
|
+
return all(c in _ALPHABET for c in cleaned)
|
|
12
|
+
|
|
13
|
+
def decode_base36(encoded: str) -> str:
|
|
14
|
+
"""
|
|
15
|
+
Decode a Base36 string to integer then interpret as UTF-8 bytes (big-endian).
|
|
16
|
+
For text use, treat as big integer to bytes.
|
|
17
|
+
"""
|
|
18
|
+
cleaned = encoded.strip().lower()
|
|
19
|
+
num = int(cleaned, 36)
|
|
20
|
+
if num == 0:
|
|
21
|
+
return ""
|
|
22
|
+
byte_length = (num.bit_length() + 7) // 8
|
|
23
|
+
return num.to_bytes(byte_length, "big").decode("utf-8")
|
|
24
|
+
|
|
25
|
+
def encode_base36(message: str) -> str:
|
|
26
|
+
"""
|
|
27
|
+
Encode a string to Base36 via big integer.
|
|
28
|
+
"""
|
|
29
|
+
data = message.encode("utf-8")
|
|
30
|
+
num = int.from_bytes(data, "big")
|
|
31
|
+
if num == 0:
|
|
32
|
+
return "0"
|
|
33
|
+
result = []
|
|
34
|
+
while num > 0:
|
|
35
|
+
num, rem = divmod(num, 36)
|
|
36
|
+
result.append(_ALPHABET[rem])
|
|
37
|
+
return "".join(reversed(result))
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# decodify/algorithms/base45.py
|
|
2
|
+
# RFC 9285 Base45
|
|
3
|
+
_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
|
|
4
|
+
_BASE = 45
|
|
5
|
+
|
|
6
|
+
def is_base45(encoded: str) -> bool:
|
|
7
|
+
"""
|
|
8
|
+
Check if the input is valid Base45.
|
|
9
|
+
Require presence of characteristic chars that distinguish from hex/base64.
|
|
10
|
+
"""
|
|
11
|
+
cleaned = encoded.strip()
|
|
12
|
+
if not cleaned or len(cleaned) < 2 or len(cleaned) % 3 == 1:
|
|
13
|
+
return False
|
|
14
|
+
if not all(c in _ALPHABET for c in cleaned):
|
|
15
|
+
return False
|
|
16
|
+
# Base45 often contains space, $, %, *, +, -, ., / or digits mixed with upper
|
|
17
|
+
# Avoid pure hex or pure digits which are more likely hex/base36
|
|
18
|
+
special = set(" $%*+-./:")
|
|
19
|
+
if not any(c in special for c in cleaned) and cleaned.isalnum() and all(c in "0123456789ABCDEFabcdef" for c in cleaned):
|
|
20
|
+
return False # looks like hex
|
|
21
|
+
# Exclude pure Morse-like (mostly . -)
|
|
22
|
+
if set(cleaned) <= set(". -/") and cleaned.count(".") + cleaned.count("-") > len(cleaned) * 0.5:
|
|
23
|
+
return False
|
|
24
|
+
return True
|
|
25
|
+
|
|
26
|
+
def decode_base45(encoded: str) -> str:
|
|
27
|
+
"""
|
|
28
|
+
Decode a Base45 string (RFC 9285).
|
|
29
|
+
"""
|
|
30
|
+
cleaned = encoded.strip()
|
|
31
|
+
result = bytearray()
|
|
32
|
+
i = 0
|
|
33
|
+
while i < len(cleaned):
|
|
34
|
+
if i + 2 < len(cleaned):
|
|
35
|
+
a = _ALPHABET.index(cleaned[i])
|
|
36
|
+
b = _ALPHABET.index(cleaned[i+1])
|
|
37
|
+
c = _ALPHABET.index(cleaned[i+2])
|
|
38
|
+
n = a + b * 45 + c * 45 * 45
|
|
39
|
+
result.append(n // 256)
|
|
40
|
+
result.append(n % 256)
|
|
41
|
+
i += 3
|
|
42
|
+
else:
|
|
43
|
+
a = _ALPHABET.index(cleaned[i])
|
|
44
|
+
b = _ALPHABET.index(cleaned[i+1])
|
|
45
|
+
n = a + b * 45
|
|
46
|
+
result.append(n)
|
|
47
|
+
i += 2
|
|
48
|
+
return bytes(result).decode("utf-8")
|
|
49
|
+
|
|
50
|
+
def encode_base45(message: str) -> str:
|
|
51
|
+
"""
|
|
52
|
+
Encode a string to Base45 (RFC 9285).
|
|
53
|
+
"""
|
|
54
|
+
data = message.encode("utf-8")
|
|
55
|
+
result = []
|
|
56
|
+
i = 0
|
|
57
|
+
while i < len(data):
|
|
58
|
+
if i + 1 < len(data):
|
|
59
|
+
n = data[i] * 256 + data[i+1]
|
|
60
|
+
c = n // (45 * 45)
|
|
61
|
+
n %= (45 * 45)
|
|
62
|
+
b = n // 45
|
|
63
|
+
a = n % 45
|
|
64
|
+
result.append(_ALPHABET[a])
|
|
65
|
+
result.append(_ALPHABET[b])
|
|
66
|
+
result.append(_ALPHABET[c])
|
|
67
|
+
i += 2
|
|
68
|
+
else:
|
|
69
|
+
n = data[i]
|
|
70
|
+
b = n // 45
|
|
71
|
+
a = n % 45
|
|
72
|
+
result.append(_ALPHABET[a])
|
|
73
|
+
result.append(_ALPHABET[b])
|
|
74
|
+
i += 1
|
|
75
|
+
return "".join(result)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# decodify/algorithms/base58.py
|
|
2
|
+
_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
3
|
+
_BASE = len(_ALPHABET)
|
|
4
|
+
|
|
5
|
+
def is_base58(encoded: str) -> bool:
|
|
6
|
+
"""
|
|
7
|
+
Check if the input looks like Base58 (Bitcoin-style).
|
|
8
|
+
"""
|
|
9
|
+
cleaned = encoded.strip()
|
|
10
|
+
if not cleaned or len(cleaned) < 4:
|
|
11
|
+
return False
|
|
12
|
+
if not all(c in _ALPHABET for c in cleaned):
|
|
13
|
+
return False
|
|
14
|
+
# Prefer strings that contain both upper and lower (typical of base58)
|
|
15
|
+
has_upper = any(c.isupper() for c in cleaned)
|
|
16
|
+
has_lower = any(c.islower() for c in cleaned)
|
|
17
|
+
has_digit = any(c.isdigit() for c in cleaned)
|
|
18
|
+
return (has_upper and has_lower) or (has_digit and (has_upper or has_lower))
|
|
19
|
+
|
|
20
|
+
def decode_base58(encoded: str) -> str:
|
|
21
|
+
"""
|
|
22
|
+
Decode a Base58 string to UTF-8 text.
|
|
23
|
+
"""
|
|
24
|
+
cleaned = encoded.strip()
|
|
25
|
+
num = 0
|
|
26
|
+
for c in cleaned:
|
|
27
|
+
num = num * _BASE + _ALPHABET.index(c)
|
|
28
|
+
if num == 0:
|
|
29
|
+
return ""
|
|
30
|
+
byte_length = (num.bit_length() + 7) // 8
|
|
31
|
+
result = num.to_bytes(byte_length, "big")
|
|
32
|
+
leading = 0
|
|
33
|
+
for c in cleaned:
|
|
34
|
+
if c == "1":
|
|
35
|
+
leading += 1
|
|
36
|
+
else:
|
|
37
|
+
break
|
|
38
|
+
return (b"\x00" * leading + result).decode("utf-8")
|
|
39
|
+
|
|
40
|
+
def encode_base58(message: str) -> str:
|
|
41
|
+
"""
|
|
42
|
+
Encode a string to Base58.
|
|
43
|
+
"""
|
|
44
|
+
data = message.encode("utf-8")
|
|
45
|
+
num = int.from_bytes(data, "big")
|
|
46
|
+
if num == 0:
|
|
47
|
+
return "1" * len(data)
|
|
48
|
+
result = []
|
|
49
|
+
while num > 0:
|
|
50
|
+
num, rem = divmod(num, _BASE)
|
|
51
|
+
result.append(_ALPHABET[rem])
|
|
52
|
+
leading = 0
|
|
53
|
+
for b in data:
|
|
54
|
+
if b == 0:
|
|
55
|
+
leading += 1
|
|
56
|
+
else:
|
|
57
|
+
break
|
|
58
|
+
return "1" * leading + "".join(reversed(result))
|