Skip to content

r4gn4r0x/python-codext

Repository files navigation

PyPiRead The DocsBuild StatusCoverage StatusPython VersionsRequirements StatusKnown VulnerabilitiesLicense

Introduction

This library extends the native codecs library (namely for adding new custom encodings and character mappings) and provides a myriad of new encodings (static or parametrized, like rot or xor), hence its named combining CODecs EXTension.

Setup

$ pip install codext

Note: Some encodings are available in Python 3 only.

Usage (CLI tool)

$ codext -i test.txt encode dna-1 GTGAGCGGGTATGTGA $ echo -en "test"| codext encode morse - . ... -

Python 3 (includes Ascii85, Base85, Base100 and braille):

$ echo -en "test"| codext encode braille ⠞⠑⠎⠞ $ echo -en "test"| codext encode base100 👫👜👪👫

Using codecs chaining:

$ 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

Usage (Python)

Getting the list of available codecs:

>>>importcodext>>>codext.list() ['ascii85', 'base85', 'base100', 'base122', ..., 'tomtom', 'dna', 'html', 'markdown', 'url', 'resistor', 'sms', 'whitespace', 'whitespace-after-before']

Usage examples:

>>>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'
>>>foriinrange(8): print(codext.encode("this is a test", "dna-%d"% (i+1))) GTGAGCCAGCCGGTATACAAGCCGGTATACAAGCAGACAAGTGAGCGGGTATGTGACTCACGGACGGCCTATAGAACGGCCTATAGAACGACAGAACTCACGCCCTATCTCAACAGATTGATTAACGCGTGGATTAACGCGTGGATGAGTGGACAGATAAACGCACAGAGACATTCATTAAGCGCTCCATTAAGCGCTCCATCACTCCAGACATAAAGCGAGACTCTGTAAGTAATTCGCGAGGTAATTCGCGAGGTAGTGAGGTCTGTATTTCGCTCTGTGTCTAACTAATTGCGCACCTAATTGCGCACCTACTCACCTGTCTATTTGCGTGTCGAGTGCCTGCCGGATATCTTGCCGGATATCTTGCTGTCTTGAGTGCGGGATAGAGTCACTCGGTCGGCCATATGTTCGGCCATATGTTCGTCTGTTCACTCGCCCATACACT>>>codext.decode("GTGAGCCAGCCGGTATACAAGCCGGTATACAAGCAGACAAGTGAGCGGGTATGTGA", "dna-1") 'this is a test'
>>>codecs.encode("this is a test", "morse") '- .... .. ... / .. ... / .- / - . ... -'>>>codecs.decode("- .... .. ... / .. ... / .- / - . ... -", "morse") 'this is a test'>>>withopen("morse.txt", 'w', encoding="morse") asf: f.write("this is a test") 14>>>withopen("morse.txt",encoding="morse") asf: 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")) ***.** . ****.** . .** .* . *** .****.**** .** .** . **. * .***. **. ** . **. **. ****. *.****.** .*

List of codecs

CodecConversionsComment
a1z26text <-> alphabet order numberskeeps words whitespace-separated and uses a custom character separator
affinetext <-> affine ciphertextaka Affine Cipher
ascii85text <-> ascii85 encoded textPython 3 only
atbashtext <-> Atbash ciphertextaka Atbash Cipher
bacontext <-> Bacon ciphertextaka Baconian Cipher
barbie-Ntext <-> barbie ciphertextaka Barbie Typewriter (N belongs to [1, 4])
baseXXtext <-> baseXXsee base encodings
baudottext <-> Baudot code bitssupports CCITT-1, CCITT-2, EU/FR, ITA1, ITA2, MTK-2 (Python3 only), UK, ...
bcdtext <-> binary coded decimal textencodes characters from their (zero-left-padded) ordinals
brailletext <-> braille symbolsPython 3 only
citrixtext <-> Citrix CTX1 ciphertextaka Citrix CTX1 passord encoding
dnatext <-> DNA-N sequenceimplements the 8 rules of DNA sequences (N belongs to [1,8])
excess3text <-> XS3 encoded textuses Excess-3 (aka Stibitz code) binary encoding to convert characters from their ordinals
graytext <-> gray encoded textaka reflected binary code
gziptext <-> Gzip-compressed textstandard Gzip compression/decompression
htmltext <-> HTML entitiesimplements entities according to this reference
ipsumtext <-> latin wordsaka lorem ipsum
klopftext <-> klopf encoded textPolybius square with trivial alphabetical distribution
leetspeaktext <-> leetspeak encoded textbased on minimalistic elite speaking rules
letter-indicestext <-> text with letter indicesencodes consonants and/or vowels with their corresponding indices
lz77text <-> LZ77-compressed textcompresses the given data with the algorithm of Lempel and Ziv of 1977
lz78text <-> LZ78-compressed textcompresses the given data with the algorithm of Lempel and Ziv of 1978
manchestertext <-> manchester encoded textXORes each bit of the input with 01
markdownmarkdown --> HTMLunidirectional
morsetext <-> morse encoded textuses whitespace as a separator
navajotext <-> Navajoonly handles letters (not full words from the Navajo dictionary)
octaltext <-> octal digitsdummy octal conversion (converts to 3-digits groups)
ordinaltext <-> ordinal digitsdummy character ordinals conversion (converts to 3-digits groups)
pkzip_deflatetext <-> deflated textstandard Zip-deflate compression/decompression
pkzip_bzip2text <-> Bzipped textstandard BZip2 compression/decompression
pkzip_lzmatext <-> LZMA-compressed textstandard LZMA compression/decompression
radiotext <-> radio wordsaka NATO or radio phonetic alphabet
resistortext <-> resistor colorsaka resistor color codes
rottext <-> rot(N) ciphertextaka Caesar cipher (N belongs to [1,25])
rotatetext <-> N-bits-rotated textrotates characters by the specified number of bits ; Python 3 only
scytaletext <-> scytale ciphertextencrypts with L, the number of letters on the rod (belongs to [1,[)
shifttext <-> shift(N) ciphertextshift ordinals with N (belongs to [1,255])
smstext <-> phone keystrokesalso called T9 code ; uses "-" as a separator for encoding, "-" or "_" or whitespace for decoding
southparktext <-> Kenny's languageconverts letters to Kenny's language from Southpark (whitespace is also handled)
tomtomtext <-> tom-tom encoded textsimilar to morse, using slashes and backslashes
urltext <-> URL encoded textaka URL encoding
xortext <-> XOR(N) ciphertextXOR with a single byte (N belongs to [1,255])
whitespacetext <-> whitespaces and tabsreplaces bits with whitespaces and tabs

A few variants are also implemented.

CodecConversionsComment
baudot-spacedtext <-> Baudot code groups of bitsgroups of 5 bits are whitespace-separated
baudot-tapetext <-> Baudot code tapeoutputs a string that looks like a perforated tape
bcd-extended0text <-> BCD-extended textencodes characters from their (zero-left-padded) ordinals using prefix bits 0000
bcd-extended1text <-> BCD-extended textencodes characters from their (zero-left-padded) ordinals using prefix bits 1111
manchester-invertedtext <-> manchester encoded textXORes each bit of the input with 10
octal-spacedtext <-> octal digits (whitespace-separated)dummy octal conversion
ordinal-spacedtext <-> ordinal digits (whitespace-separated)dummy character ordinals conversion
southpark-icasetext <-> Kenny's languagesame as southpark but case insensitive
whitespace_after_beforetext <-> lines of whitespaces[letter]whitespacesencodes characters as new characters with whitespaces before and after according to an equation described in the codec name (e.g. "whitespace+2*after-3*before")

About

Python codecs extension

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python100.0%