Skip to main content

Pure Python implementation of the binary-to-text encoding from RFC 1751, S/Key

Project description

This is a Pure-Python implementation of RFC 1751.

Using this small library, you can turn binary strings (for example IDs or passwords) into small sequences of short English words. For example:

EB33 F77E E73D 4053

would become:

TIDE ITCH SLOW REIN RULE MOT

The algorithm turns a 64-bit string into 6 English words and vice versa. Two bits of parity are included in the sequence of words, which allow detecting an invalid or corrupted phrase.

Usage

>>> # Simple conversion from string or bytes
>>> rfc1751.bytes_to_string([204, 172, 42, 237, 89, 16, 86, 190])
'RASH BUSH MILK LOOK BAD BRIM'
>>> rfc1751.bytes_to_string(b'\xCC\xAC\x2A\xED\x59\x10\x56\xBE')
'RASH BUSH MILK LOOK BAD BRIM'

>>> # You can specify the separator or get a sequence
>>> rfc1751.bytes_to_string(b'\xCC\xAC\x2A\xED\x59\x10\x56\xBE', sep='-').lower()
'rash-bush-milk-look-bad-brim'
>>> rfc1751.bytes_to_words(b'\xCC\xAC\x2A\xED\x59\x10\x56\xBE')
['RASH', 'BUSH', 'MILK', 'LOOK', 'BAD', 'BRIM']

>>> # Conversion back
>>> rfc1751.string_to_bytes('RASH BUSH MILK LOOK BAD BRIM')
b'\xCC\xAC\x2A\xED\x59\x10\x56\xBE'
>>> list(rfc1751.string_to_bytes('RASH BUSH MILK LOOK BAD BRIM'))
[204, 172, 42, 237, 89, 16, 86, 190]

>>> # You can specify the separator or give a sequence
>>> rfc1751.string_to_bytes('rash-bush-milk-look-bad-brim', sep='-')
b'\xCC\xAC\x2A\xED\x59\x10\x56\xBE'
>>> rfc1751.words_to_bytes(['rash', 'bush', 'milk', 'look', 'bad', 'brim'])
b'\xCC\xAC\x2A\xED\x59\x10\x56\xBE'

>>> # You can also use a custom alphabet as long as it is 2048 words
>>> custom_rfc1751 = rfc1751.Rfc1751(custom_2048_words)
>>> custom_rfc1751.bytes_to_string([204, 172, 42, 237, 89, 16, 86, 190])
'SMILE GENUINE ROBUST RATE AIR GAME'
>>> list(custom_rfc1751.string_to_bytes('SMILE GENUINE ROBUST RATE AIR GAME'))
[204, 172, 42, 237, 89, 16, 86, 190]

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

rfc1751-1.0.0.tar.gz (8.8 kB view hashes)

Uploaded Source

Built Distribution

rfc1751-1.0.0-py3-none-any.whl (8.9 kB view hashes)

Uploaded Python 3

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