I have the following challenge sending UDP packet:
The packet is 40 bytes long where all fields constant except some counter and checksum.
header='\xaf\x18\x25\x25'
message= 'ABCDEFGHIGKLMNOPQRTSUVXYZ0123456'
i=1
#do some checksum calculation and store result into the checksum variable
message=header + chr(i) + data + chr(checksum >>8) + chr(checksum & 0xFF)
sock.sendto(message.encode('utf-8'), (DST_IP, int(DST_PORT)))
However, looking into a wireshark, I can see that the message is 43 bytes where i have a 0xC2 at first location instead of the actual header 1st byte and 0XC3 and 0xC2 before the checksums MSB & LSB (which are the 3 extra bytes)
Any ssugestion what is the issue and how to fix it?
changed the encoding solved the issue
sock.sendto(message.encode('charmap'), (DST_IP, int(DST_PORT)))
Related
I checked hash length from node data, like below(include '0x').
block hash: 66
transaction hash: 66
receipt root: 66
address: 40
Is it always a fixed length?
Or is it variable length?
Yes, it's always fixed length.
Block hash is calculated using the keccak256 algorithm that always results in 32 bytes (64 hex characters prepended by 0x) no matter the input length.
Same goes for transaction hash and receipt root hash.
An address is always the last 20 bytes (40 hex charaters prepended by 0x) of the public key hash.
I have my bytes stored as string values
like this in file D:\source.txt
208
203
131
132
148
128
128
128
128
128
I just want to read them, and store in another file
I am quite new for powershell, so wrote program like this
$bytes = New-Object System.Collections.ArrayList
foreach($line in [System.IO.File]::ReadLines("D:\source.txt"))
{
[void]$bytes.Add([System.Convert]::ToByte($line));
}
[System.IO.File]::WriteAllBytes("D:\target.zip",[Byte[]]$bytes.ToArray());
So from my undestanding it should get string value, convert it to byte
store it in ArrayList, convert ArrayList to byte array and wrote it to file
And everything goes ok, even if i do echo [Byte[]]$bytes.ToArray() i see correct value
But result file is corrupted, and when i check it byte by byte i see next values
-48
-53
-125
-124
-108
-128
-128
-128
-128
-128
Seems like WriteAllBytes shift my byte values by 128, but why and where?
I am not very professional with powershell, and i cant find anything related in documentation
So can you suggest how i can correct this?
Thanks you for any info
Thanks, i actually found what is the problem. Cause for corruption was incorrect library method for converting from java byte(values from -128...127) to unsigned powershell byte And in hex redactor i`ve got int(8) representation, which is corresponds, if check in powershell(uint) bytes are shown correctly Thanks for help
I am trying to decode this base64 string using VB.NET
System.Convert.FromBase64String("AgBgVvBR0apvj88GZFp/0ontNtFIcsJoVTachX30kURDlK010Mv9/yv1yLXXr4mqII5z2Hzx9FlGxA==")
And it returns 58 bytes. If I convert from Base64 on any online base64 decode program I get 32 bytes..??
What am I doing wrong?
Your base64 string is 80 characters. Removing the two = padding characters, you get 78 base64 characters. Each one represents 6 bits.
The length of the decoded string should be 78*6/8 = 58 bytes. So, your code is producing the correct output.
The online tools you're using are probably trying to decode into a UTF-8 or ASCII printable characters (which is not the case for your input). That's why you're only seeing less bytes in the output.
I want to send two bytes which represent an unsigned short in big-endian to server via TCP. But net-send only supports string parameter.
Could anyone tell me how to do this with newLISP?
It works now.
CODE: SELECT ALL
(set 'socket (net-connect "localhost" 8889))
16
(set 'size (pack ">d" 19))
"\000\019"
(net-send socket size)
2
pack returns a string buffer that contains my two bytes, net-send sends the string to server.
My C++ server got two bytes, 0 and 19.
Thanks.
I used wireshark, under our protocol we send and receive 5 bytes in payload, even wireshark say 5 bytes received , but show : 0000010001 : 10 digit.
How i read it?
It's hexadecimal - each two digits correspond to one byte.