+int CmdLFNedapChk(const char *Cmd){
+ //301600714021BE
+ uint8_t data[256] = { 0x30, 0x16, 0x00, 0x71, 0x40, 0x21, 0xBE};
+ int len = 0;
+ param_gethex_ex(Cmd, 0, data, &len);
+
+ len = ( len == 0 ) ? 5 : len>>1;
+
+ PrintAndLog("Input: [%d] %s", len, sprint_hex(data, len));
+
+ //uint8_t last = GetParity(data, EVEN, 62);
+ //PrintAndLog("TEST PARITY:: %d | %d ", DemodBuffer[62], last);
+
+ uint8_t cl = 0x1D, ch = 0x1D, carry = 0;
+ uint8_t al, bl, temp;
+
+ for (int i =len; i >= 0; --i){
+ al = data[i];
+ for (int j = 8; j > 0; --j) {
+
+ bl = al ^ ch;
+ //printf("BL %02x | CH %02x \n", al, ch);
+
+ carry = (cl & 0x80) ? 1 : 0;
+ cl <<= 1;
+
+ temp = (ch & 0x80) ? 1 : 0;
+ ch = (ch << 1) | carry;
+ carry = temp;
+
+ carry = (al & 0x80) ? 1 : 0;
+ al <<= 1;
+
+ carry = (bl & 0x80) ? 1 : 0;
+ bl <<= 1;
+
+ if (carry) {
+ cl ^= 0x21;
+ ch ^= 0x10;
+ }
+ }
+ }
+
+ PrintAndLog("Nedap checksum: 0x%X", ((ch << 8) | cl) );
+ return 0;
+}
+
+