I have a rather idiotic newbie question.
I'm getting a fobkey read from an rfid reader i got a while back. It's coming in as ASCII hex i believe and on the pi using python i'd like to convert it to the actual key that is written on the fob.
so from
"0C0032667C24" to 0003303036 which is written the fob.
I feel like an idiot but i've tried in ipython everything to convert the ASCII/hex to that digit and nada.
Also i think the last two ASCII characters are checksum keys it's a 125khz rfid reader which doesn't seem to be sold on adafruit anymore though..
so i think checksum is 24
any help much appreciated for python help.
fob key conversion
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: fob key conversion
"0C0032667C24" is hex. Not sure what the 0c is, but I'll guess it's the total length of the string. 24 does appear to be some sort of checksum. So that leaves you with 0032667C hex, which is ...wait for it... 3303036 decimal!
- prussia
- Posts: 27
- Joined: Mon Jan 21, 2013 8:07 pm
Re: fob key conversion
Hi,
hmm thanks for the reply but I sort of stated all that in my post already? I was trying to get help with the python part but I think I figured it out after my post. All but how to use checksum to test
hmm thanks for the reply but I sort of stated all that in my post already? I was trying to get help with the python part but I think I figured it out after my post. All but how to use checksum to test
Code: Select all
fob_decimal = int(fob[2:10],16)
str(fob_decimal)
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: fob key conversion
Sorry. I misunderstood the question.
The checksum looks like the accumulated XOR of the message bytes, including the 0C. At least, 0C ^ 00 ^ 32 ^ 66 ^ 7C is 24.
The checksum looks like the accumulated XOR of the message bytes, including the 0C. At least, 0C ^ 00 ^ 32 ^ 66 ^ 7C is 24.
- prussia
- Posts: 27
- Joined: Mon Jan 21, 2013 8:07 pm
Re: fob key conversion
he he,
No problem. so i'm trying to write something in ipython to test the xor but i have no idea how i'd convert the fob string. add the 0x then XOR. seems in python I have to run:
to get 0x24 out (checksum) but not sure how to compose the above. nudge, hint or sample code would be nice :)
No problem. so i'm trying to write something in ipython to test the xor but i have no idea how i'd convert the fob string. add the 0x then XOR. seems in python I have to run:
Code: Select all
hex(0x0C ^ 0x00 ^ 0x32 ^ 0x66 ^ 0x7C)
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: fob key conversion
I'm definitely not the guy to ask about python, but I think you'd do something like
That includes the checksum in the calculation, so the result should always be zero if you have a valid string.
Of course, you might want to code this up as a loop, if your strings can change in length.
Code: Select all
check = int(fob[0:1],16) ^ int(fob[2:3],16) ^ int(fob[4:5],16) ^ int(fob[6:7],16) ^ int(fob[8:9],16) ^ int(fob[10:11],16)
Of course, you might want to code this up as a loop, if your strings can change in length.
- prussia
- Posts: 27
- Joined: Mon Jan 21, 2013 8:07 pm
Re: fob key conversion
hmm,
yeah I tried that but seems i need the 0x part too. not sure.
yeah I tried that but seems i need the 0x part too. not sure.
Please be positive and constructive with your questions and comments.