wtf

WTF is white tight feet.

I use Python to complete this play. If you don’t have it, you can try to download it and enjoy it.

Given the hex string, hex string mean the base16 encode. base16 make each eight bit turn to two hex, then convert to three characters.

  • use bytes.fromhex to unhexlify
  • then use b64encode in base64 module
1
2
3
4
5
6
import base64
data = '49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d'
data_byte = bytes.fromhex(data)
data_b64encode = base64.b64encode(data_byte)
print(f'{data_byte=}')
print(f'{data_b64encode=}')

Certainly, we want to write small program to use in the future.

Then use some tricks to increase skill about module.

  • def: def mean create a function to use repeatedly.
  • __name__=="__main__": create a alone environment.
1
2
3
4
5
6
7
8
9
from base64 import b16decode, b64encode
def hex2bas64(data_hex: bytes) -> bytes:
return b64encode(b16decode(data_hex, casefold=True))
if __name__ == '__main__':
data_hex = '49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d'
data_byte = bytes.fromhex(data_hex)
b64_data = hex2bas64(data_hex)
print(f'{data_byte = }')
print(f'{b64_data = }')

本文作者 : wtfff
本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议(CC BY-NC-SA 4.0)进行许可。This blog is under a CC BY-NC-SA 4.0 Unported License
本文链接 : http://im0use.github.io/2022/05/16/hex2base64/

本文最后更新于 天前,文中所描述的信息可能已发生改变