50 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
1
answer
100
views
Python Byte-encoding functions do not work as expected
I'm trying to convert a hexadecimal number,
like the stack address 0x7ffd6fa90940,
into its corresponding Byte representation b'\x40\x09\xa9\x6f\xfd\x7f\x00\x00'.
Just like how it is represented in ...
0
votes
2
answers
129
views
Python3 bytes to string with real hex bytes
I've seen a lot of posts about this subject but I haven't found the solution I'm looking for (despite lot of attempts ...).
In a nutshell, when migrating one of my libraries from Python2 to 3, whose ...
0
votes
1
answer
200
views
python: hex to bin with binascii.a2b_hex results in binascii.Error: Odd-length string
i am trying to convert a hex string to bin using binascii.a2b_hex but i get binascii.Error: Odd-length string only with some strings, not everytime.
for example this is the string throwing the error: ...
0
votes
3
answers
322
views
How can i convert my hex values to binary in Python? binascii.a2b_hex error
Hello when I use binascii.a2b_hex, error is occured.
There is no error message but the return value is wrong.
Here is the data and the resule.
Input : FEB10AA86764FFFF
Output : b'\xfe\xb1\n\xa8gd\xff\...
0
votes
1
answer
249
views
Mac address conversion to bytes
I am trying to convert a mac address in hex like this: 00453645f200
to a Mac address in bytes like this:
x00\x45\x36\x45\xf2\x00
But if I use binascii.unhexlify, the result is like this:
b'\x00E6E\xf2\...
0
votes
2
answers
115
views
Pack into c types and obtain the binary value back
I'm using the following code to pack an integer into an unsigned short as follows,
raw_data = 40
# Pack into little endian
data_packed = struct.pack('<H', raw_data)
Now I'm trying to unpack the ...
1
vote
1
answer
604
views
How do I know which endian to use in struct.unpack() when converting hexadecimal string to float?
I have data in form of hexadecimal string and I convert it to float as:
import struct, binascii
a = '0X437A1AF6'
x = struct.unpack('>f', binascii.unhexlify(str(a)[2:]))
print(x[0])
I get the right ...
0
votes
0
answers
1k
views
Python: binascii.Error: Invalid base64-encoded string
I am processing the email files from Amazon SES. The email contains a pdf file encoded with base64.
Content-Type: application/octet-stream; name="IN081AKC.pdf"
Content-Transfer-Encoding: ...
1
vote
1
answer
528
views
I want to read the hexadecimal number of a binary file sequentially by 6 bytes
import binascii
import sys
from os.path import getsize
target = './'+sys.argv[1]
with open(target,'rb+') as f:
file_size = getsize(target)
string1 = f.read(6)
print("Size : %d&...
3
votes
1
answer
1k
views
Writing hex string into a binary file
I am trying to write an hex string into a file using python 2.7 so that when opened with HxD I can retrieve the same hex values.
The following code works fine on multiple input strings, but when the ...
0
votes
0
answers
35
views
unhexlify always needs pairs
I have a simple piece of Python code where I want to xor two hex strings
and unhexlify the result as below
def _xor(s1, s2):
return hex(int(s1, 16) ^ int(s2, 16))[2:]
if __name__ == "...
2
votes
1
answer
554
views
Differences of the ord() function between Python 2.7 and 3.9 [duplicate]
Good morning people!
I've been trying to convert this code written in Python 2 to Python 3.It's a simple function to encrypt strings using XOR. What I have so far:
import binascii
def encrypt(content:...
1
vote
1
answer
1k
views
How to get the sha256 of a 'binary' array in Python
given the following Python code:
bits = [0]*256 # for simplicity (actually it's more like (0|1)^n)
binstr = "" # make string containing all 'bits'
for el in bits:
binstr += str(el)
...
1
vote
1
answer
902
views
Calculating CRC32 checksum on string
I am in the process of bringing an API up from 2.7 to 3.8. It is built to communicate with an agent over a TCP socket. I am having an issue with a checksum not being calculated right. I get a message ...
-1
votes
1
answer
576
views
Xbee image transfer python
Hi there i'm quite new with xBee and struggle with data transferring. My objective is to take picture with Raspberry pi wide and send it back to computer via xBee by turn that image to hexlify code. ...