Skip to main content
This package provides codecs useful for hacking and hacking related CTFs.

There are several codecs avaliable once you import this module. To get
a full list you can use the CODECS_IN_FILE dictionary which is used to
populated the codec entries:

>>> pprint(sorted(CODECS_IN_FILE.keys()))
['ascii85',
'bin',
'entity',
'entityhex',
'morse',
'rot1',
'rot10',
'rot11',
'rot12',
'rot13',
'rot14',
'rot15',
'rot16',
'rot17',
'rot18',
'rot19',
'rot2',
'rot20',
'rot21',
'rot22',
'rot23',
'rot24',
'rot25',
'rot3',
'rot4',
'rot5',
'rot6',
'rot7',
'rot8',
'rot9',
'url',
'yenc']


You should first notice all the "rot" entries. The `rot-13` codec is
provided by default. The rest of these provide similar functionality
for rapid checks of shift ciphers:

>>> pprint(['ymj vznhp gwtbs ktc ozruji tajw ymj qfed itl'.decode('rot%d' % i) for i in xrange(1,26)])
[u'xli uymgo fvsar jsb nyqtih sziv xli pedc hsk',
u'wkh txlfn eurzq ira mxpshg ryhu wkh odcb grj',
u'vjg swkem dtqyp hqz lworgf qxgt vjg ncba fqi',
u'uif rvjdl cspxo gpy kvnqfe pwfs uif mbaz eph',
u'the quick brown fox jumped over the lazy dog',
u'sgd pthbj aqnvm enw itlodc nudq sgd kzyx cnf',
u'rfc osgai zpmul dmv hskncb mtcp rfc jyxw bme',
u'qeb nrfzh yoltk clu grjmba lsbo qeb ixwv ald',
u'pda mqeyg xnksj bkt fqilaz kran pda hwvu zkc',
u'ocz lpdxf wmjri ajs ephkzy jqzm ocz gvut yjb',
u'nby kocwe vliqh zir dogjyx ipyl nby futs xia',
u'max jnbvd ukhpg yhq cnfixw hoxk max etsr whz',
u'lzw imauc tjgof xgp bmehwv gnwj lzw dsrq vgy',
u'kyv hlztb sifne wfo aldgvu fmvi kyv crqp ufx',
u'jxu gkysa rhemd ven zkcfut eluh jxu bqpo tew',
u'iwt fjxrz qgdlc udm yjbets dktg iwt apon sdv',
u'hvs eiwqy pfckb tcl xiadsr cjsf hvs zonm rcu',
u'gur dhvpx oebja sbk whzcrq bire gur ynml qbt',
u'ftq cguow ndaiz raj vgybqp ahqd ftq xmlk pas',
u'esp bftnv mczhy qzi ufxapo zgpc esp wlkj ozr',
u'dro aesmu lbygx pyh tewzon yfob dro vkji nyq',
u'cqn zdrlt kaxfw oxg sdvynm xena cqn ujih mxp',
u'bpm ycqks jzwev nwf rcuxml wdmz bpm tihg lwo',
u'aol xbpjr iyvdu mve qbtwlk vcly aol shgf kvn',
u'znk waoiq hxuct lud pasvkj ubkx znk rgfe jum']

"the quick brown fox jumped over the lazy dog" <- bingo

My favorite codec, and reason I started the project, is of course
morse encoding:

>>> 'SOS'.encode('morse')
'... --- ...'

>>> '... --- ...'.decode('morse')
'SOS'

Morse code is doesn't support the full ascii character set, nor does
it support casing so keep that in mind:

>>> 'asdf'.encode('morse').decode('morse')
'ASDF'

>>> "THIS IS MORSE CODE!".encode('morse')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/hex/progz/python/hackercodecs/hackercodecs/__init__.py", line 247, in morse_encode
assert c in morse_map, "Unencodable character '%s' found. Failing" % c
AssertionError: Unencodable character '!' found. Failing

Another favorite of mine is `bin`. It's only a few lines, but there's
no reason to write those same lines over and over again each CTF. Just
let hackercodecs handle that for you:

>>> 'asdf'.encode('bin')
'01100001011100110110010001100110'

>>> '01100001011100110110010001100110'.decode('bin')
'asdf'

It also counts bits to make sure you're not doing something stupid:

'0110000101110011011001000110011'.decode('bin')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/hex/progz/python/hackercodecs/hackercodecs/__init__.py", line 275, in bin_decode
assert (len(input) % 8) == 0, AssertionError: Wrong number of bits, 31 is not divisible by 8

If you ever hack on web challenges you know how nice it is to have
urllib handle url encoding. Since we already have this library for
hacker codecs, I figured it would be worth while to just add
that. Everything in one place is nice sometimes:

>>> "' or ''='".encode('url')
'%27%20or%20%27%27%3D%27'
>>> '%27%20or%20%27%27%3D%27'.decode('url')
"' or ''='"

Likewise entity encoding can be nice when attacking some XML based
challenge:

>>> "]]>&xxe;".encode('entity')
']]&gt;&amp;xxe;'

>>> ']]&gt;&amp;xxe;'.decode('entity')
']]>&xxe;'

Or the hex equivilent

>>> '<script>alert("1")</script>'.encode('entityhex')
'&#x3c;script&#x3e;alert("1")&#x3c;/script&#x3e;'


Then we get a little less common. If you're from the internet you
Might know that usenet uses yEnc:

>>> print repr('asdf'.encode('yenc'))
'\x8b\x9d\x8e\x90'

>>> '\x8b\x9d\x8e\x90'.decode('yenc')
'asdf'

And if you work on PDFs at all, you may have seen ascii85. It's kind
of like base64, but not really at all:

>>> 'asdf'.encode('ascii85')
'@<5sk'

>>> '@<5sk'.decode('ascii85')
'asdf'

In the future I'll probably add more things
(http://en.wikipedia.org/wiki/Binary-to-text_encoding)... after
porting everything to python 3. If there are any special requests for
encodings you'd like me to add feel free to write them yourself and
submit a patch. It should be pretty damn easy to add a codec based on
the code below.

Metadata

Release files for hackercodecs 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distributions (sdists)

Source distribution for hackercodecs 0.3
File Size Uploaded Provenance
hackercodecs-0.3.tar.gz 7.1 kB Without provenance Details
hackercodecs-0.3.linux-x86_64.tar.gz 12.0 kB Without provenance Details

Release files / hackercodecs-0.3.tar.gz

Download URL hackercodecs-0.3.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
78d6892a272d9e22b4d2381245a6f36be5dd2ce1527b07cb4f82280f8355b818
BLAKE2b-256 checksum
How to use checksums
65e577073a3b79f79451999a725b8cf5615e1920ada53dc1e8170546496c2882
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / hackercodecs-0.3.linux-x86_64.tar.gz

Download URL hackercodecs-0.3.linux-x86_64.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a72175902c5ea1c8e8618b1686168e33366b6f764c73bb9e70466909621ac922
BLAKE2b-256 checksum
How to use checksums
4a38c62877e022e480dbcbdf6a065a84501cf1924e941c820490a1e57e4dbb74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for hackercodecs 0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page