c# - Python XOR on hex and string (parity check function) -
I am running into problems with hex value and python. I am trying to write a function that does the same XOR and returns a hex value.
Actually I am trying to convert this C # code into Python:
Private Byte [] AddParity (string_in) {byte parity = 0x7f; & Lt; Byte & gt; _out = new list & lt; Byte & gt; (); ASCIIEncoding asc = new ASCIIEncoding (); Byte [] bytes = asc.GetBytes (_in + '\ r'); Foreign (bytes in Byte BT) {Parati ^ = BT; _out.Add (BT); } _out.Add (parity); Return _out.ToArray (); }
Can anyone tell me in the right direction?
equality = 0x7f parities = [int (item, 16) ^ "4e 7f 2b" .split ()] # or perhaps parity = [ord (item) ^ paragraph for item in "somestering"]
I think you use it as some kind of checksum For the bit in "Somestring"
equality = 0x7f bits [=]: parity ^ = ord (bit) parity & amp; = 0xFF # Extension width bits .append (bit) bits Append (Samata)
You can do this to make the checksum more dragon
This is the answer you want to do < / Strong>
bytestring = "vTest \ r" bits = CRR (0x7f) + bitsetring checksum = low (lambda x, y: cr (ord (x) ^ ord (y)) And 0xff), bits) Message = ('0x76', '0x54', '0x65', '0x73', '0x74', '0xd', '0x32', and 'check box'] # Ser.write (message) / Code>
If you want to see the hex value
print map (hex, parity)
or th E binary to view
print map (bin, paratiss)
Comments
Post a Comment