Python cryptographic XOR string and hexadecimal

topic description

the hexadecimal string output after sha256 encryption is to be XOR with the contents of an array (32 array elements, each with a length of one byte). My question is how to convert a hexadecimal string to the corresponding binary and XOR in the array.

sources of topics and their own ideas

The main problem of

is: each character in hexadecimal character is represented by a byte (8bit), and the original binary bit represented by each character is only (4bit), and every two such data is XOR with data such as 0x0D in the array. How should this be realized?

Dec.10,2021

The key to performing bit operations in

python is that both operators must be of the same type and length. Each element of the
B type array is a 1-byte int, so you can convert your [hexadecimal string] into a sequence of 1-byte int. The quickest way is to convert directly to a byte string.

>>> import array
>>> my_arr = array.array('B', range(32)) -sharpB
>>> my_arr
array('B', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31])
>>> hex_str = '68656c6c6f20776f726c6421' -sharp
>>> hex_bytes = bytes.fromhex(hex_str) -sharp
>>> hex_bytes -sharp
b'hello world!'
>>> hex_bytes[0] ^ my_arr[0] -sharp
104
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3d825-2c395.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3d825-2c395.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?