二进制转布莱叶盲文转义

发布时间 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         00000021    !    01110122    "    000010    ⠐
23    #    001111    ⠼
24    $    11010125    %    10010126    &    11110127    '    001000    ⠄
28    (    11101129    )    011111    ⠾
2A    *    100001    ⠡
2B    +    001101    ⠬
2C    ,    000001    ⠠
2D    -    001001    ⠤
2E    .    000101    ⠨
2F    /    00110030    0    00101131    1    01000032    2    01100033    3    01001034    4    01001135    5    01000136    6    01101037    7    01101138    8    01100139    9    001010    ⠔
3A    :    100011    ⠱
3B    ;    000011    ⠰
3C    <    110001    ⠣
3D    =    111111    ⠿
3E    >    001110    ⠜
3F    ?    10011140    @    00010041    A    10000042    B    11000043    C    10010044    D    10011045    E    10001046    F    11010047    G    11011048    H    11001049    I    010100    ⠊
4A    J    010110    ⠚
4B    K    101000    ⠅
4C    L    111000    ⠇
4D    M    101100    ⠍
4E    N    101110    ⠝
4F    O    10101050    P    11110051    Q    11111052    R    11101053    S    01110054    T    01111055    U    10100156    V    11100157    W    01011158    X    10110159    Y    101111    ⠽
5A    Z    101011    ⠵
5B    [    010101    ⠪
5C    \    110011    ⠳
5D    ]    110111    ⠻
5E    ^    000110    ⠘
5F    _    000111    ⠸