48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
import stdio
|
|
import stdlib
|
|
import string
|
|
import binascii
|
|
import t, c
|
|
|
|
|
|
|
|
|
|
def main222():
|
|
binascii.init_binascii()
|
|
raw: str = "HelloWorld!"
|
|
raw_length: t.CInt = 11
|
|
|
|
stdio.printf("你好\n")
|
|
|
|
hex_out: str = binascii.b2a_hex(raw, raw_length)
|
|
if hex_out:
|
|
stdio.printf("Hex: %s\n", hex_out)
|
|
free(hex_out)
|
|
|
|
crc_val: t.CUnsignedInt = binascii.crc32(raw, raw_length, 0)
|
|
stdio.printf("CRC32: %u\n", crc_val)
|
|
|
|
b64_out: str = binascii.b2a_base64(raw, raw_length)
|
|
if b64_out:
|
|
stdio.printf("Base64: %s\n", b64_out)
|
|
free(b64_out)
|
|
|
|
uu_out: str = binascii.b2a_uu(raw, raw_length)
|
|
if uu_out:
|
|
stdio.printf("UU: %s\n", uu_out)
|
|
free(uu_out)
|
|
|
|
hqx_in: t.CArray[t.CChar, 4] = ['A', 'B', 'C', '\0']
|
|
hqx_crc: t.CUnsignedShort = 0
|
|
hqx_out: str
|
|
unhqx: str
|
|
hqx_out, hqx_crc = binascii.b2a_hqx(hqx_in, 3)
|
|
unhqx, hqx_crc = binascii.a2b_hqx(hqx_out)
|
|
stdio.printf("HQX Test: ABC -> %s -> %s (CRC:%u)\n", hqx_out, unhqx, hqx_crc)
|
|
free(hqx_out); free(unhqx)
|
|
|
|
adler_val: t.CUnsignedInt = binascii.adler32(raw, raw_length, 1)
|
|
stdio.printf("Adler32: %u\n", adler_val)
|
|
|
|
stdio.printf("Bye\n")
|