CLI tool
codext has a Command-Line Interface tool.
Using Codext from the terminal¶
The help message describes everything to know:
usage: codext [-h] [-i INFILE] [-o OUTFILE] [-s] {encode,decode,guess,search} ...
Codecs Extension (CodExt) 1.8.1
Author : Alexandre D'Hondt (alexandre.dhondt@gmail.com)
Copyright: © 2019-2021 A. D'Hondt
License : GPLv3 (https://www.gnu.org/licenses/gpl-3.0.fr.html)
Source : https://github.com/dhondta/python-codext
This tool allows to encode/decode input strings/files with an extended set of codecs.
positional arguments:
{encode,decode,guess,search}
command to be executed
encode encode input using the specified codecs
decode decode input using the specified codecs
guess try guessing the decoding codecs
search search for codecs
optional arguments:
-h, --help show this help message and exit
-i INFILE, --input-file INFILE
input file (if none, take stdin as input)
-o OUTFILE, --output-file OUTFILE
output file (if none, display result to stdout)
-s, --strip-newlines strip newlines from input
usage examples:
- codext search bitcoin
- codext -i file.b32 decode base32
- codext encode morse < to_be_encoded.txt
- echo "test" | codext encode base100
- echo -en "test" | codext encode braille -o test.braille
- codext encode base64 < to_be_encoded.txt > text.b64
- echo -en "test" | codext encode base64 | codext encode base32
- echo -en "mrdvm6teie6t2cq=" | codext encode upper | codext decode base32 | codext decode base64
- echo -en "test" | codext encode upper reverse base32 | codext decode base32 reverse lower
- echo -en "test" | codext encode upper reverse base32 base64 morse
- echo -en "test" | codext encode base64 gzip | codext guess
- echo -en "test" | codext encode base64 gzip | codext guess gzip -c base
- codext strength base64 gzip
- echo -en "secret" | codext strength base64 rot-13
- codext compose
- codext compose -a alphanumeric -l 4 -k mysecret -m mychain -n
- codext show rle
- codext show base64-url rot-13 example-macro
- codext -i secret.bin analyze
- echo -en "test" | codext encode vigenere-rainbow | codext analyze
- codext -i ciphertext.txt crack vigenere
- echo -en "rglpxoiodltueosefdomerndat" | codext crack columnar -l 3
Input/output
STDIN can be used as shown in an example from the help message, like when using the common Linux tool base64.
Unless an output file is specified, the result is displayed in STDOUT.
Encodings chaining
Encodings can be chained as shown in the last examples of the help message. This can be practical for quickly manipulating data.
Codecs documentation
codext show displays the documentation of the given codecs, encodings or macros: the codec's name, category and module, then the docstring of this module (for a native codec, the one of its module from the encodings package), or the chain of encodings of a macro. An unknown name is reported with similar names (e.g. codext show vigener suggests vigenere).
Analysis and cracking
codext analyze reports the statistical properties of the input (alphabet, randomness, letter frequencies, ...) with hints on what it may be, and codext crack recovers the key of a keyed cipher (e.g. vigenere, vernam or columnar) from the input ; see Analysis and cracking.
Graphical tool¶
codext-gui opens a window where a text, or a file, can be dropped to be guessed at once (as with codext guess). A text can also be pasted, or a file opened (Open file...), then guessed with the Guess button, and a text or a file can be given as argument (e.g. codext-gui secret.txt). The input and the output are shown side by side, above the search parameters and the results (the panes can be resized by dragging their separators). Below the input, a one-line summary tells its length and what it may be (from its analysis, e.g. "It only holds hexadecimal characters"), and likewise below the output.

The chains of codecs found are listed with a preview of their outputs ; the output of the selected one is shown next to the input, and can be copied to the clipboard (Copy, or a double-click on the result), saved to a file as is (Save..., e.g. for binary data) or moved to the input with the left arrow between both areas (e.g. to decode it further) ; the right arrow shows the input in the output area, as the first result ((input)), e.g. to copy or save it.
Once the codec of every layer is set (see Layers below), the input can also be decoded with these codecs, in their order (Decode), or encoded with them, in the reverse order (Encode), so that decoding the result with the same layers gives the input back. Characters that a codec does not handle (e.g. the braces of a flag for a cipher on letters) are left as is, and the status bar tells which layers did so.
The search runs in a separate process, so that the window remains responsive and the search can be cancelled (the Guess button becomes Cancel), bounded by the timeout. It stops at the first output that matches the chosen condition (stop function):
- By default, it searches a single layer of encoding (Layers: 1, guessed) for the regular expression entered in the Pattern field (
regexstop function), case-insensitive with Ignore case. The list of the field suggests common patterns (e.g. a flag format, a URL or an email address) and the recently used ones. - Without a pattern, the search looks for a natural language text (
text_strictstop function) rather than failing. - The codecs considered can be restricted to some categories (Codecs, all by default) and to those whose names match a regular expression (Codec names, e.g.
base|rot, or^url$for an exact name), within the selected categories ; the number of selected codecs is shown next to them. This speeds the search up when the kind of encoding is known (as-idoes withcodext guess). - The codec of each layer (in decoding order, the first being the outermost one) can be set, either picked from the list of codecs or typed with its parameters (e.g.
rot-13orxor-42) ; typing the start of a name (e.g.c) lists the matching codecs below the field (from 3 characters or several words, the names holding them too, e.g.fenceorrot prog), to be picked with Up/Down and Enter or a click (Escape closes the list), Enter also completing the name when a single codec matches, while the layers left to (guess) are guessed among the selected codecs. The solutions are then only searched once every set layer is decoded, the guessed layers after the last set one being optional (e.g. with 3 layers set to (guess),base64and (guess): a guessed layer, then Base64, then optionally another guessed layer). This speeds the search up a lot when some layers are known (as thelayersparameter does withcodext.guess). - Rank (Ctrl+R) shows how guessing ranks the codecs of the first layer that is not set yet (among the selected codecs), once the input is decoded with the layers set before it (or of the layer following them when every layer is set): a window lists the codecs that decode it, from the most probable one, with their scores (and a bar relative to the best one) and outputs. Set as layer N (or a double-click) sets the selected codec for this layer, e.g. to then rank the codecs of the next layer. As the search, the ranking can be cancelled (Escape) and stops at the timeout.
- Crack (Ctrl+K) recovers the key of the cipher of the first layer set to a cipher without its key (e.g.
vigenere,affine,vernam,columnar, orrailfencewhose encodings for the guess mode are tried), once the input is decoded with the layers set before it, ascodext crackdoes: a window lists the most likely keys with the scores of their outputs (how much they look like a text), the outputs matching the Pattern (e.g. the prefix of a flag) coming first. Set as layer N (or a double-click) sets the selected encoding, with its key, for this layer. The key search stops at the timeout. - With Find all matches, the search does not stop at the first output that matches, but goes on until all the layers are explored or the timeout is reached, listing every match (as with
codext guess --do-not-stop). - For an unknown chain of encodings, choose more layers ; the
textstop function may stop at an intermediate encoding that looks like text (e.g. Base64), unliketext_strict.
| Shortcut | Action |
|---|---|
| Ctrl+Enter | Guess |
| Escape | Cancel the search, the ranking or the cracking |
| Ctrl+R | Rank the codecs of the first layer that is not set |
| Ctrl+K | Crack the cipher of the first layer set to a cipher without its key |
| Ctrl+O | Open a file |
| Ctrl+L | Clear the input and the results |
| Ctrl+A | Select all the text (a paste with Ctrl+V then replaces it) |
| Ctrl+Shift+C | Copy the output of the selected result |
| Ctrl+S | Save the output of the selected result |
The window follows the light or dark mode of the system (Theme: System), checked every few seconds, unless the light or dark theme is chosen. The mode of the system is read from the registry on Windows, from the global AppleInterfaceStyle setting on macOS and, on Linux, from the GTK_THEME environment variable, the color scheme or GTK theme of GNOME (gsettings) or the color scheme of KDE.

The settings (stop function, pattern, recent patterns, layers and their codecs, timeout, Find all matches, selected categories and codec names, theme and window size) are remembered between sessions, in ~/.codext-gui.json.
Optional dependencies
The tool relies on Tkinter, part of the standard library but packaged separately on some systems (e.g. sudo apt-get install python3-tk on Debian/Ubuntu). Drag-and-drop requires the tkinterdnd2 package, installed with pip install codext[gui] ; without it, the text can still be pasted or opened.
Execution examples¶
Scenario 1: 2-stages encoded flag
Creating the payload:
$ echo "A somewhat weird F1@9 !" | codext encode rotate-3 base58
pwTDSWRUbXTuMQs5EDgKpjgW8MiJVw1
From this point, the only thing we know is that we are searching for "flag" (with eventually other characters, i.e. leetspeak).
$ echo "A somewhat weird F1@9 !" | codext encode rotate-3 base58 | codext guess -f flag
Codecs: base58, rotate-3
A somewhat weird F1@9 !
Executing the previous command will take a few tens of seconds. With few stages to be guessed, using the scoring heuristic can be far quicker to get to the right output. The following takes less than a second.
$ echo "A somewhat weird F1@9 !" | codext encode rotate-3 base58 | codext guess -f flag --heuristic
Codecs: base58, rotate-3
A somewhat weird F1@9 !
Scenario 2: Multi-stage-encoded flag
Creating the payload:
$ echo "A somewhat weird F1@9 !" | codext encode barbie-1 base32 morse
.... -.-- --.- --. -- ....- - -.- -- . ..... -..- --. ..--- .-.. .. . .- ..... .-- -.-. ..... -.. --- -. --.- --.- . --. -- .-. --... ..-. ..- --.- -.-. -- -...- -...- -...-
When looking at the string, it is easy to figure out it is morse. The problem, at this point, is that this codec is case-insensitive and always returns lowercase characters, as shown hereafter.
$ echo "A somewhat weird F1@9 !" | codext encode barbie-1 base32 morse | codext decode morse
hyqgm4tkme5xg2liea5wc5donqqegmr7fuqcm===
In order to get it guessed as Base32, it is necessary to put it back to uppercase (in other words, decode from lowercase).
$ echo "A somewhat weird F1@9 !" | codext encode barbie-1 base32 morse | codext decode morse lowercase
HYQGM4TKME5XG2LIEA5WC5DONQQEGMR7FUQCM===
Now that we know we are searching for something with "flag" (with eventually other characters), we can use the predefined "flag" stop function.
$ echo "A somewhat weird F1@9 !" | codext encode barbie-1 base32 morse | codext decode morse lowercase | codext guess -f flag
Codecs: base32, barbie
A somewhat weird F1@9 !
Scenario 3: Base-encoded rotated shifted secret (English) message
Creating the payload:
$ echo "My super secret string" | codext encode shift-1 rotate-2 base58 base64
NDNxaFdieXh0Z29XOVZpWWpjRGNpRWgyZE44Z2FNU0g=
First, we shall simplify as much as possible ; we can easily guess that Base64 was used as the first encoding scheme:
$ echo "aDRuUnFGaWZTblJqRmZReFJIdVZweGp4cFA4Y0NS" | codext rank
[+] 1.00002: base62
[+] 0.99401: base64
[+] 0.70806: rotate-1
[+] 0.70806: rotate-2
[+] 0.70806: rotate-3
[+] 0.70806: rotate-4
[+] 0.70806: rotate-5
[+] 0.70806: rotate-6
[+] 0.70806: rotate-7
[+] 0.70806: rotate-left-1
$ echo "aDRuUnFGaWZTblJqRmZReFJIdVZweGp4cFA4Y0NS" | codext decode base62
%¤q ´!.[æ&[fÿhbð^
$ echo "aDRuUnFGaWZTblJqRmZReFJIdVZweGp4cFA4Y0NS" | codext decode base64
h4nRqFifSnRjFfQxRHuVpxjxpP8cCR
Afterwards, we can still try to simplify ;
$ echo "aDRuUnFGaWZTblJqRmZReFJIdVZweGp4cFA4Y0NS" | codext decode base64 | codext rank
[+] 1.00185: base58
[+] 0.99091: base62
[+] 0.67001: rotate-1
[+] 0.67001: rotate-2
[+] 0.67001: rotate-3
[+] 0.67001: rotate-4
[+] 0.67001: rotate-5
[+] 0.67001: rotate-6
[+] 0.67001: rotate-7
[+] 0.67001: rotate-left-1
From here, let us assume that base58 is effectively the right second-stage encoding. Guessing the two remaining encodings with no more information will now take a few seconds. As multiple outputs can be recognized as normal text, we will use the "-s" option not to stop on the first output successfully decoded as text. Moreover, if we have the intuition that the output shall be English text, we can use a more refined stop function like "lang_en" with the "-f" option.
$ echo "aDRuUnFGaWZTblJqRmZReFJIdVZweGp4cFA4Y0NS" | codext decode base64 | codext decode base58 | codext guess -s -f lang_en
[...]
[+] rotate-2, rot-1: My!super!secret!string
[+] rotate-2, rot-23: Qc!wytiv!wigvix!wxvmrk
[+] rotate-2, shift-1: My super secret string
[+] rotate-2, shift-20: :f\r`b]R_\r`RP_Ra\r`a_V[T
[...]
[+] rotate-left-6, shift-1: My super secret string
^C^C^C
We can then stop the research with Ctrl+C. The right output has been found !