Search code examples
binaryhexrfid

Convert EM4x02 ID to Hitag2 Value


I've been working on an RFID project to produce our own RFID cards to work on our existing timeclocks and readers.

I've got most of the work done, and have been able to successfully write a Hitag2 card using the value of page 4 & 5 from another card (so basically copying the card) then changing the config bit which makes it act like an EM4x02 which allows our readers to read it.

What I'm struggling with is trying to relate the hex code on page4/5 to the output you get when scanning as an EM4x..

The values of the hitag page 4/5 are FF800000/003EDF10. This translates to 0000001EBC when read as an EM4x.

Does anybody have an idea on how this translation is done? I've tried using the methods in RFIDIOT but that doesn't seem to work for this.


Solution

  • I've managed to find how this is done after finding a hitag2 datasheet from 1999 (the only one I could find that explains the bits when hitag is in public mode A)

    Firstly, convert the number you want on the EM4 card to hex.

    Convert that hex into binary.

    Split the binary into 4 bit chunks, then work out the even parity for each section and add it to the end of each chunk. (So you'll end up with 5 bits per chunk)

    Then, work out the even parity of each column in the data (i.e first character of all chunks, then second etc. But ignoring the parity bit you added) and add these 4 bytes to the binary string.

    Then add the correct amount of zeros at the start to ensure the data section has 50 bits.

    Once you have the data section sorted, add 9 bits of 1 to the beginning (header) and a final 0 to the very end of the binary.

    Your whole binary string should be 64 bits long.

    Convert this to hex and split it in half. You can then write these onto pages 4/5 of a Hitag2 card.

    You then need to change the configuration bit to 0x02 for the tag to work in public mode a.