dhondta/python-codext

GitHub: dhondta/python-codext

Python 编解码扩展库,提供 120+ 种编码格式支持和 AI 猜测功能的 CLI 工具,用于编解码任意数据。

Stars: 295 | Forks: 26

CodExt Tweet

Encode/decode anything.

[![PyPi](https://img.shields.io/pypi/v/codext.svg)](https://pypi.python.org/pypi/codext/) [![阅读文档](https://readthedocs.org/projects/python-codext/badge/?version=latest)](https://python-codext.readthedocs.io/en/latest/?badge=latest) [![构建状态](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/8eb4e8ba83085251.svg)](https://github.com/dhondta/python-codext/actions/workflows/python-package.yml) [![覆盖率状态](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/aeb77c6955085252.svg)](#) [![Python 版本](https://img.shields.io/pypi/pyversions/codext.svg)](https://pypi.python.org/pypi/codext/) [![已知漏洞](https://snyk.io/test/github/dhondta/python-codext/badge.svg?targetFile=requirements.txt)](https://snyk.io/test/github/dhondta/python-codext?targetFile=requirements.txt) [![DOI](https://zenodo.org/badge/236679865.svg)](https://zenodo.org/badge/latestdoi/236679865) [![许可证](https://img.shields.io/pypi/l/codext.svg)](https://pypi.python.org/pypi/codext/) [**CodExt**](https://github.com/dhondta/python-codext) 是一个(兼容 Python2-3)的库,它扩展了原生 [`codecs`](https://docs.python.org/3/library/codecs.html) 库(主要用于添加新的自定义编码和字符映射),并提供了 **120+ 种新编解码器**,因此得名 *CODecs EXTension*(编解码器扩展)。它还具有 **猜测模式**,用于解码多层编码,并提供方便的 **CLI 工具**。 ``` $ pip install codext ``` 想要贡献新的编解码器? | 想要贡献新的宏? :----------------------------------:|:------------------------------------: 先查看[文档](https://python-codext.readthedocs.io/en/latest/howto.html)
然后 [PR](https://github.com/dhondta/python-codext/pulls) 你的新编解码器 | [PR](https://github.com/dhondta/python-codext/pulls) 你更新后的 [`macros.json`](https://github.com/dhondta/python-codext/blob/main/codext/macros.json) 版本 ## :mag: 演示

Using CodExt from the command line

Using base tools from the command line

Using the unbase command line tool

## :computer: 用法(主 CLI 工具) Tweet on codext ``` $ codext -i test.txt encode dna-1 GTGAGCGGGTATGTGA $ echo -en "test" | codext encode morse - . ... - $ echo -en "test" | codext encode braille ⠞⠑⠎⠞ $ echo -en "test" | codext encode base100 👫👜👪👫 ``` ### 链式编解码器 ``` $ echo -en "Test string" | codext encode reverse gnirts tseT $ echo -en "Test string" | codext encode reverse morse --. -. .. .-. - ... / - ... . - $ echo -en "Test string" | codext encode reverse morse dna-2 AGTCAGTCAGTGAGAAAGTCAGTGAGAAAGTGAGTGAGAAAGTGAGTCAGTGAGAAAGTCAGAAAGTGAGTGAGTGAGAAAGTTAGAAAGTCAGAAAGTGAGTGAGTGAGAAAGTGAGAAAGTC $ echo -en "Test string" | codext encode reverse morse dna-2 octal 101107124103101107124103101107124107101107101101101107124103101107124107101107101101101107124107101107124107101107101101101107124107101107124103101107124107101107101101101107124103101107101101101107124107101107124107101107124107101107101101101107124124101107101101101107124103101107101101101107124107101107124107101107124107101107101101101107124107101107101101101107124103 $ echo -en "AGTCAGTCAGTGAGAAAGTCAGTGAGAAAGTGAGTGAGAAAGTGAGTCAGTGAGAAAGTCAGAAAGTGAGTGAGTGAGAAAGTTAGAAAGTCAGAAAGTGAGTGAGTGAGAAAGTGAGAAAGTC" | codext -d dna-2 morse reverse test string ``` ### 使用宏 ``` $ codext add-macro my-encoding-chain gzip base63 lzma base64 $ codext list macros example-macro, my-encoding-chain $ echo -en "Test string" | codext encode my-encoding-chain CQQFAF0AAIAAABuTgySPa7WaZC5Sunt6FS0ko71BdrYE8zHqg91qaqadZIR2LafUzpeYDBalvE///ug4AA== $ codext remove-macro my-encoding-chain $ codext list macros example-macro ``` ## :computer: 用法(基础 CLI 工具) Tweet on unbase ``` $ echo "Test string !" | base122 *.7!ft9�-f9Â $ echo "Test string !" | base91 "ONK;WDZM%Z%xE7L $ echo "Test string !" | base91 | base85 B2P|BJ6A+nO(j|-cttl% $ echo "Test string !" | base91 | base85 | base36 | base58-flickr QVx5tvgjvCAkXaMSuKoQmCnjeCV1YyyR3WErUUErFf $ echo "Test string !" | base91 | base85 | base36 | base58-flickr | base58-flickr -d | base36 -d | base85 -d | base91 -d Test string ! ``` ``` $ echo "Test string !" | base91 | base85 | base36 | base58-flickr | unbase -m 3 Test string ! $ echo "Test string !" | base91 | base85 | base36 | base58-flickr | unbase -f Test Test string ! ``` ## :computer: 用法(Python) 获取可用编解码器列表: ``` >>> import codext >>> codext.list() ['ascii85', 'base85', 'base100', 'base122', ..., 'tomtom', 'dna', 'html', 'markdown', 'url', 'resistor', 'sms', 'whitespace', 'whitespace-after-before'] >>> codext.encode("this is a test", "base58-bitcoin") 'jo91waLQA1NNeBmZKUF' >>> codext.encode("this is a test", "base58-ripple") 'jo9rA2LQwr44eBmZK7E' >>> codext.encode("this is a test", "base58-url") 'JN91Wzkpa1nnDbLyjtf' >>> codecs.encode("this is a test", "base100") '👫👟👠👪🐗👠👪🐗👘🐗👫👜👪👫' >>> codecs.decode("👫👟👠👪🐗👠👪🐗👘🐗👫👜👪👫", "base100") 'this is a test' >>> for i in range(8): print(codext.encode("this is a test", "dna-%d" % (i + 1))) GTGAGCCAGCCGGTATACAAGCCGGTATACAAGCAGACAAGTGAGCGGGTATGTGA CTCACGGACGGCCTATAGAACGGCCTATAGAACGACAGAACTCACGCCCTATCTCA ACAGATTGATTAACGCGTGGATTAACGCGTGGATGAGTGGACAGATAAACGCACAG AGACATTCATTAAGCGCTCCATTAAGCGCTCCATCACTCCAGACATAAAGCGAGAC TCTGTAAGTAATTCGCGAGGTAATTCGCGAGGTAGTGAGGTCTGTATTTCGCTCTG TGTCTAACTAATTGCGCACCTAATTGCGCACCTACTCACCTGTCTATTTGCGTGTC GAGTGCCTGCCGGATATCTTGCCGGATATCTTGCTGTCTTGAGTGCGGGATAGAGT CACTCGGTCGGCCATATGTTCGGCCATATGTTCGTCTGTTCACTCGCCCATACACT >>> codext.decode("GTGAGCCAGCCGGTATACAAGCCGGTATACAAGCAGACAAGTGAGCGGGTATGTGA", "dna-1") 'this is a test' >>> codecs.encode("this is a test", "morse") '- .... .. ... / .. ... / .- / - . ... -' >>> codecs.decode("- .... .. ... / .. ... / .- / - . ... -", "morse") 'this is a test' >>> with open("morse.txt", 'w', encoding="morse") as f: f.write("this is a test") 14 >>> with open("morse.txt",encoding="morse") as f: f.read() 'this is a test' >>> codext.decode(""" = X : x n r y Y y p a ` n | a o h ` g o z """, "whitespace-after+before") 'CSC{not_so_invisible}' >>> print(codext.encode("An example test string", "baudot-tape")) ***.** . * ***.* * . .* * .* . * ** .* ***.** ** .** .* * . * *. * .* * *. * *. * * . * *. * *. * ***. *.* ***.* * .* ``` ## :page_with_curl: 编解码器列表 #### [BaseXX](https://python-codext.readthedocs.io/en/latest/enc/base.html) - [X] `base1`: 无用,但为了完整性而保留 - [X] `base2`: 简单转换为二进制(带有反转字母表的变体) - [X] `base3`: 转换为三进制(带有反转字母表的变体) - [X] `base4`: 转换为四进制(带有反转字母表的变体) - [X] `base8`: 简单转换为八进制(带有反转字母表的变体) - [X] `base10`: 简单转换为十进制 - [X] `base11`: 带有 "*a*" 的数字转换 - [X] `base16`: 简单转换为十六进制(带有数字和字母反转字母表的变体) - [X] `base26`: 转换为字母表字符 - [X] `base32`: 根据 RFC4648 的经典转换及其所有变体([zbase32](https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt)、扩展十六进制、[geohash](https://en.wikipedia.org/wiki/Geohash)、[Crockford](https://www.crockford.com/base32.html)) - [X] `base36`: [Base36](https://en.wikipedia.org/wiki/Base36) 转换为字母和数字(带有反转两组字符的变体) - [X] `base45`: [Base45](https://datatracker.ietf.org/doc/html/draft-faltstrom-base45-04.txt) DRAFT 算法(带有反转字母和数字的变体) - [X] `base58`: [Base58](https://en.bitcoinwiki.org/wiki/Base58) 的多个版本(bitcoin、flickr、ripple) - [X] `base62`: [Base62](https://en.wikipedia.org/wiki/Base62) 转换为大小写字母和数字(带有字母和数字反转的变体) - [X] `base63`: 类似于 `base62`,添加了 "`_`" - [X] `base64`: 根据 RFC4648 的经典转换及其 URL(或 *file*)变体(也包含字母和数字反转的变体) - [X] `base67`: 使用更多特殊字符的自定义转换(也包含字母和数字反转的变体) - [X] `base85`: Base85 的所有变体([Ascii85](https://fr.wikipedia.org/wiki/Ascii85)、[z85](https://rfc.zeromq.org/spec/32)、[Adobe](https://dencode.com/string/ascii85)、[(x)btoa](https://dencode.com/string/ascii85)、[RFC1924](https://datatracker.ietf.org/doc/html/rfc1924)、[XML](https://datatracker.ietf.org/doc/html/draft-kwiatkowski-base85-for-xml-00)) - [X] `base91`: [Base91](http://base91.sourceforge.net) 自定义转换 - [X] `base100`(或 *emoji*): [Base100](https://github.com/AdamNiederer/base100) 自定义转换 - [X] `base122`: [Base100](http://blog.kevinalbs.com/base122) 自定义转换 - [X] `base-genericN`: 参见 [base encodings](https://python-codext.readthedocs.io/en/latest/enc/base.html);支持任何可能的进制 此类别还在 `base85` 编解码器中包含 `ascii85`、`adobe`、`[x]btoa`、`zeromq`。 #### [二进制](https://python-codext.readthedocs.io/en/latest/enc/binary.html) - [X] `baudot`: 支持 CCITT-1、CCITT-2、EU/FR、ITA1、ITA2、MTK-2(仅限 Python3)、UK 等 - [X] `baudot-spaced`: `baudot` 的变体;5 位组以空格分隔 - [X] `baudot-tape`: `baudot` 的变体;输出类似于穿孔纸带的字符串 - [X] `bcd`: _Binary Coded Decimal_(二进制编码十进制),根据其(左侧补零的)序数编码字符 - [X] `bcd-extended0`: `bcd` 的变体;使用前缀位 `0000` 根据(左侧补零的)序数编码字符 - [X] `bcd-extended1`: `bcd` 的变体;使用前缀位 `1111` 根据(左侧补零的)序数编码字符 - [X] `excess3`: 使用 Excess-3(又名 Stibitz code)二进制编码根据序数转换字符 - [X] `gray`: 又名反射二进制码 - [X] `manchester`: 将输入的每一位与 `01` 进行异或 - [X] `manchester-inverted`: `manchester` 的变体;将输入的每一位与 `10` 进行异或 - [X] `rotateN`: 将字符旋转指定的位数(*N* 属于 [1, 7];仅限 Python 3) #### [通用](https://python-codext.readthedocs.io/en/latest/enc/common.html) - [X] `a1z26`: 保持单词以空格分隔,并使用自定义字符分隔符 - [X] `cases`: 一组与大小写相关的编码(包括 camel-、kebab-、lower-、pascal-、upper-、snake- 和 swap-case、slugify、capitalize、title) - [X] `dummy`: 一组简单的编码(包括 integer、replace、reverse、word-reverse、substite 和 strip-spaces) - [X] `octal`: 伪八进制转换(转换为 3 位组) - [X] `octal-spaced`: `octal` 的变体;伪八进制转换,处理空格分隔符 - [X] `ordinal`: 伪字符序数转换(转换为 3 位组) - [X] `ordinal-spaced`: `ordinal` 的变体;伪字符序数转换,处理空格分隔符 #### [压缩](https://python-codext.readthedocs.io/en/latest/enc/compressions.html) - [X] `gzip`: 标准 Gzip 压缩/解压 - [X] `lz77`: 使用 1977 年的 Lempel 和 Ziv 算法压缩给定数据 - [X] `lz78`: 使用 1978 年的 Lempel 和 Ziv 算法压缩给定数据 - [X] `pkzip_deflate`: 标准 Zip-deflate 压缩/解压 - [X] `pkzip_bzip2`: 标准 BZip2 压缩/解压 - [X] `pkzip_lzma`: 标准 LZMA 压缩/解压 #### [密码学](https://python-codext.readthedocs.io/en/latest/enc/crypto.html) - [X] `affine`: 又名 Affine Cipher(仿射密码) - [X] `atbash`: 又名 Atbash Cipher(埃特巴什码) - [X] `bacon`: 又名 Baconian Cipher(培根密码) - [X] `barbie-N`: 又名 Barbie Typewriter(芭比打字机)(*N* 属于 [1, 4]) - [X] `citrix`: 又名 Citrix CTX1 密码编码 - [X] `railfence`: 又名 Rail Fence Cipher(栅栏密码) - [X] `rotN`: 又名 Caesar cipher(凯撒密码)(*N* 属于 [1,25]) - [X] `scytaleN`: 使用杆上的字母数进行加密(*N* 属于 [1,[) - [X] `shiftN`: 移位序数(*N* 属于 [1,255]) - [X] `xorN`: 与单个字节进行异或(*N* 属于 [1,255]) #### [哈希](https://python-codext.readthedocs.io/en/latest/enc/hashing.html) - [X] `blake`: 包括 BLAKE2b 和 BLAKE2s(仅限 Python 3;依赖于 `hashlib`) - [X] `checksums`: 包括 Adler32 和 CRC32(依赖于 `zlib`) - [X] `crypt`: Unix 的密码 crypt 哈希(仅限 Python 3 和 Unix;依赖于 `crypt`) - [X] `md`: 又名 Message Digest(消息摘要);包括 MD4 和 MD5(依赖于 `hashlib`) - [X] `sha`: 又名 Secure Hash Algorithms(安全哈希算法);包括 SHA1、224、256、384、512(Python2/3),以及 SHA3-224、-256、-384 和 -512(仅限 Python 3;依赖于 `hashlib`) - [X] `shake`: 又名 SHAKE 哈希(仅限 Python 3;依赖于 `hashlib`) #### [语言](https://python-codext.readthedocs.io/en/latest/enc/languages.html) - [X] `braille`: 众所周知的盲文语言(仅限 Python 3) - [X] `ipsum`: 又名 lorem ipsum - [X] `galactic`: 又名银河字母表或 Minecraft 附魔语言(仅限 Python 3) - [X] `leetspeak`: 基于极简的精英发言规则 - [X] `morse`: 使用空格作为分隔符 - [X] `navajo`: 仅处理字母(而非纳瓦霍词典中的完整单词) - [X] `radio`: 又名 NATO 或无线电语音字母表 - [X] `southpark`: 将字母转换为《南方公园》中 Kenny 的语言(也处理空格) - [X] `southpark-icase`: `southpark` 的不区分大小写变体 - [X] `tap`: 将文本转换为击代码,通常被囚犯使用 - [X] `tomtom`: 类似于 `morse`,使用斜杠和反斜杠 #### [其他](https://python-codext.readthedocs.io/en/latest/enc/others.html) - [X] `dna`: 实现 DNA 序列的 8 条规则(N 属于 [1,8]) - [X] `letter-indices`: 用对应的索引编码辅音和/或元音 - [X] `markdown`: 从 Markdown 到 HTML 的单向编码 #### [隐写术](https://python-codext.readthedocs.io/en/latest/enc/stegano.html) - [X] `hexagram`: 使用 Base64 并将结果编码为 [易经六十四卦](https://en.wikipedia.org/wiki/Hexagram_%28I_Ching%29) 字符集(如此处[实现](https://github.com/qntm/hexagram-encode)) - [X] `klopf`: 又名 Klopf code;具有简单字母分布的 Polybius 方阵 - [X] `resistor`: 又名电阻色码 - [X] `rick`: 又名 Rick cipher(Rick 密码)(参考 Rick Astley 的歌曲 "*Never gonna give you up*") - [X] `sms`: 也称为 _T9 code_;使用 "`-`" 作为编码的分隔符,使用 "`-`" 或 "`_`" 或空格作为解码的分隔符 - [X] `whitespace`: 用空格和制表符替换位 - [X] `whitespace_after_before`: `whitespace` 的变体;根据编解码器名称中描述的方程式(例如 "`whitespace+2*after-3*before`"),将字符编码为带有前后空格的新字符 #### [Web](https://python-codext.readthedocs.io/en/latest/enc/web.html) - [X] `html`: 根据[此参考](https://dev.w3.org/html5/html-author/charref)实现实体 - [X] `url`: 又名 URL 编码 ## :clap: 支持者 [![@dhondta/python-codext 的 Stargazers 仓库名单](https://reporoster.com/stars/dark/dhondta/python-codext)](https://github.com/dhondta/python-codext/stargazers) [![@dhondta/python-codext 的 Forkers 仓库名单](https://reporoster.com/forks/dark/dhondta/python-codext)](https://github.com/dhondta/python-codext/network/members)

Back to top

标签:AI猜测, Base编码, CTF工具, DNS 反向解析, Python, 加密解密, 威胁情报, 字符集, 密码学, 开发者工具, 手动系统调用, 扩展库, 摩斯密码, 数据转换, 文本处理, 文档结构分析, 无后门, 本体建模, 漏洞搜索, 编码转换, 编解码工具, 网络安全, 逆向工具, 隐写术, 隐私保护