二进制转布莱叶盲文转义

发布时间 2023-08-26 20:31:10作者: willingyut

输入s二进制数据

TYPE_HEX = 0
TYPE_ASCII = 1
TYPE_BINARY = 2
TYPE_BRAILLE = 3

with open('lookup_table.txt', 'r') as f:
    rows = f.read().splitlines()
table = list(map(lambda x: x.split('\t'), rows))

def convert(text_array, in_type=TYPE_BINARY, out_type=TYPE_ASCII, sep=''):
    output = []

    input_table = list(map(lambda x: x[in_type], table))
    output_table = list(map(lambda x: x[out_type], table))

    for item in text_array:
        index = input_table.index(item.upper())
        output.append(output_table[index])

    return sep.join(output)

s='100100011100010100100100011110110100000111110001101001100100110000111010001111100110010100111000111000001111100100000101011111'
x = []
for i in range(0,len(s),6):
    x.append(s[i:i+6])

y=convert(x, TYPE_BINARY, TYPE_BRAILLE)
print(y)
#⠉⠎⠊⠉⠞⠋⠸⠣⠥⠉⠃⠗⠼⠙⠊⠇⠇⠼⠉⠨⠾ z
=convert(y, TYPE_BRAILLE, TYPE_HEX) print(z)
#4353494354465F3C554342522344494C4C23432E29
print(bytes.fromhex(z).decode())
#CSICTF_<UCBR#DILL#C.)

输入结果为CSICTF_<UCBR#DILL#C.),实际上需要转换,将所有的大写转成小写,'_>'转成'{','.)'转成'}',#C对应3,#D对应4,如此类推

即结果为csictf{ucbr4ill3}

 

lookup_table.txt

 

Hex    ASCII    Binary    Braille
20         000000    ⠀
21    !    011101    ⠮
22    "    000010    ⠐
23    #    001111    ⠼
24    $    110101    ⠫
25    %    100101    ⠩
26    &    111101    ⠯
27    '    001000    ⠄
28    (    111011    ⠷
29    )    011111    ⠾
2A    *    100001    ⠡
2B    +    001101    ⠬
2C    ,    000001    ⠠
2D    -    001001    ⠤
2E    .    000101    ⠨
2F    /    001100    ⠌
30    0    001011    ⠴
31    1    010000    ⠂
32    2    011000    ⠆
33    3    010010    ⠒
34    4    010011    ⠲
35    5    010001    ⠢
36    6    011010    ⠖
37    7    011011    ⠶
38    8    011001    ⠦
39    9    001010    ⠔
3A    :    100011    ⠱
3B    ;    000011    ⠰
3C    <    110001    ⠣
3D    =    111111    ⠿
3E    >    001110    ⠜
3F    ?    100111    ⠹
40    @    000100    ⠈
41    A    100000    ⠁
42    B    110000    ⠃
43    C    100100    ⠉
44    D    100110    ⠙
45    E    100010    ⠑
46    F    110100    ⠋
47    G    110110    ⠛
48    H    110010    ⠓
49    I    010100    ⠊
4A    J    010110    ⠚
4B    K    101000    ⠅
4C    L    111000    ⠇
4D    M    101100    ⠍
4E    N    101110    ⠝
4F    O    101010    ⠕
50    P    111100    ⠏
51    Q    111110    ⠟
52    R    111010    ⠗
53    S    011100    ⠎
54    T    011110    ⠞
55    U    101001    ⠥
56    V    111001    ⠧
57    W    010111    ⠺
58    X    101101    ⠭
59    Y    101111    ⠽
5A    Z    101011    ⠵
5B    [    010101    ⠪
5C    \    110011    ⠳
5D    ]    110111    ⠻
5E    ^    000110    ⠘
5F    _    000111    ⠸