Base64

过程

word: test

characterbin
A-Za-z0-9+/0-63
each characterasciibin8 length
t116111010001110100
e101110010101110100
s115111001101110011
t116111010001110100

将每个字符 8 位 2进制 ASCII code 拼接在一起

001110100001110100001110011001110100

每六位切割,替换为 base64 table 字符
当不足6位时,补零

6 lengthcharacter
011101d
000110G
010101V
110011z
011101d
000000A
补了4个0

dGVzdA==

from string import ascii_uppercase, ascii_lowercase, digits

base64_table = ascii_uppercase + ascii_lowercase + digits + '+/'


def encode(words: str) -> str:  # base64 encode
    strings = ''.join([bin(ord(_)).replace('0b', '').rjust(8, '0') for _ in words])
    strings += '0' * ((len(strings) // 6 + 1) * 6 - len(strings)) if len(strings) % 6 != 0 else ''
    return ''.join([base64_table[int(strings[6 * i: 6 * (i + 1)], 2)] for i in range(len(strings) // 6)])


def decode(base64: str) -> str:   # base64 decode
    strings = ''.join([bin(base64_table.index(_)).replace('0b', '').rjust(6, '0') for _ in base64])
    decoded = ''.join([chr(int(strings[8 * _: 8 * (_ + 1)], 2)) for _ in range(len(strings) // 8)])
    return decoded

def base_steg(base64: list) -> str:  # base64 steg
    steg_string, steg_msg = '', ''
    for i in base64:
        i = i.replace('=', '')
        strings = ''.join([bin(base64_table.index(_)).replace('0b', '').rjust(6, '0') for _ in i])
        steg_string += strings[(len(strings) - len(strings) // 8 * 8) * -1:] if len(strings) % 8 != 0 else ''
    for i in range(len(steg_string) // 8):
        cha = chr(int(steg_string[i * 8: (i + 1) * 8], 2))
        steg_msg += cha if cha in base64_table else ''
    return steg_msg
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇