Skip to main content

Native codecs extension

Project description

PyPi Read The Docs Build Status Coverage Status Python Versions Requirements Status Known Vulnerabilities License

Codecs Extension

This library extends the native codecs library and provides some new encodings (static or parametrized, like rot-N or xor-N).

Codec Conversions Comment
affine text <-> affine ciphertext aka Affine Cipher
ascii85 text <-> ascii85 encoded text Python 3 only
atbash text <-> Atbash ciphertext aka Atbash Cipher
bacon text <-> Bacon ciphertext aka Baconian Cipher
barbie-N text <-> barbie ciphertext aka Barbie Typewriter (N belongs to [1, 4])
baseXX text <-> baseXX see base encodings
baudot text <-> Baudot code bits supports CCITT-1, CCITT-2, EU/FR, ITA1, ITA2, MTK-2 (Python3 only), UK, ...
braille text <-> braille symbols Python 3 only
dna text <-> DNA-N sequence implements the 8 rules of DNA sequences (N belongs to [1,8])
html text <-> HTML entities implements entities according to this reference
leetspeak text <-> leetspeak encoded text based on minimalistic elite speaking rules
markdown markdown --> HTML unidirectional
morse text <-> morse encoded text uses whitespace as a separator
octal text <-> octal digits dummy octal conversion (converts to 3-digits groups)
ordinal text <-> ordinal digits dummy character ordinals conversion (converts to 3-digits groups)
radio text <-> radio words aka NATO or radio phonetic alphabet
resistor text <-> resistor colors aka resistor color codes
rot text <-> rot(N) ciphertext aka Caesar cipher (N belongs to [1,25])
shift text <-> shift(N) ciphertext shift ordinals with N (belongs to [1,255])
sms text <-> phone keystrokes also called T9 code ; uses "-" as a separator for encoding, "-" or "_" or whitespace for decoding
url text <-> URL encoded text aka URL encoding
xor text <-> XOR(N) ciphertext XOR with a single byte (N belongs to [1,255])
whitespace text <-> whitespaces and tabs replaces bits with whitespaces and tabs

A few variants are also implemented.

Codec Conversions Comment
baudot-spaced text <-> Baudot code groups of bits groups of 5 bits are whitespace-separated
baudot-tape text <-> Baudot code tape outputs a string that looks like a perforated tape
octal-spaced text <-> octal digits (whitespace-separated) dummy octal conversion
ordinal-spaced text <-> ordinal digits (whitespace-separated) dummy character ordinals conversion
whitespace_after_before text <-> lines of whitespaces[letter]whitespaces encodes 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")

Setup

This library is available on PyPi and can be simply installed using Pip:

$ pip install codext

or

$ pip3 install codext

Note: Some more encodings are available when installing in Python 3.

Usage (from terminal)

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

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

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

Usage (within Python)

Example with Base58:

>>> 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'

Example with Base100 (emoji's):

>>> codecs.encode("this is a test", "base100")
'👫👟👠👪🐗👠👪🐗👘🐗👫👜👪👫'
>>> codecs.decode("👫👟👠👪🐗👠👪🐗👘🐗👫👜👪👫", "base100")
'this is a test'

Example with DNA sequence encoding:

>>> 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'

Example with morse:

>>> 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'

Example with whitespaces before and after:

>>> 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}'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codext-1.4.7.tar.gz (47.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page