byte[] iso14443a_crc(byte[] Data) // DESFireSAM crc16 do not invert the result
{
int bt;
int wCrc = 0x6363;
int j = 0;
int t8 = 0;
int t9 = 0;
int tA = 0;
int Len = Data.length;
final int maskB = 0x0000000000000000FF;
final int maskW = 0x00000000000000FFFF;
do
{
bt = Data[j++] & maskB;
bt = (bt^(wCrc & 0x00FF)) & maskB;
bt = (bt^(bt<<4)) & maskB;
t8 = (bt << 8) & maskW;
t9 = (bt<<3) & maskW;
tA = (bt>>4) & maskW;
wCrc = (wCrc >> 8)^(t8^t9^tA) & maskW;
}
while (j < Len);
byte[] bb = new byte[2];
bb[0] = (byte) (wCrc & maskB);
bb[1] = (byte) ((wCrc >>8) & maskB);
return bb;
}
30 March 2011
DESFire SAM crc16
Subscribe to:
Post Comments (Atom)
Hi Skinner,
ReplyDeleteIs it possible to implement this algorithm only using short variables without using int, Since I need to use this inside the javacard applet.