跳转到主要内容

纯Python实现的RFC 1751的二进制到文本编码,S/Key

项目描述

这是RFC 1751的纯Python实现。

使用这个小型库,您可以将二进制字符串(例如ID或密码)转换为短英语单词的序列。例如

EB33 F77E E73D 4053

将变成

TIDE ITCH SLOW REIN RULE MOT

该算法将64位字符串转换为6个英语单词,反之亦然。单词序列中包含两个校验位,这允许检测无效或损坏的短语。

用法

>>> # 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]

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定要选择哪个,请了解更多关于安装软件包的信息。

源代码分发

rfc1751-1.0.0.tar.gz (8.8 kB 查看哈希值)

上传时间: 源代码

构建分发

rfc1751-1.0.0-py3-none-any.whl (8.9 kB 查看哈希值)

上传时间 Python 3

支持