CHG: merged the forum user @jason 's fixes to LEGIC. *UNTESTED*

CHG: changed the CRC implementations.
This commit is contained in:
iceman1001 2016-07-28 21:41:44 +02:00
parent 83dad64b91
commit 3e134b4c20
16 changed files with 1368 additions and 163 deletions

View file

@ -9,15 +9,13 @@
//-----------------------------------------------------------------------------
#include "util.h"
#include "proxmark3.h"
#define MAX_BIN_BREAK_LENGTH (3072+384+1)
#ifndef _WIN32
#include <termios.h>
#include <sys/ioctl.h>
int ukbhit(void)
{
int ukbhit(void) {
int cnt = 0;
int error;
static struct termios Otty, Ntty;
@ -553,4 +551,20 @@ uint32_t SwapBits(uint32_t value, int nrbits) {
newvalue ^= ((value >> i) & 1) << (nrbits - 1 - i);
}
return newvalue;
}
}
/*
ref http://www.csm.ornl.gov/~dunigan/crc.html
Returns the value v with the bottom b [0,32] bits reflected.
Example: reflect(0x3e23L,3) == 0x3e26
*/
uint32_t reflect(uint32_t v, int b) {
uint32_t t = v;
for ( int i = 0; i < b; ++i) {
if (t & 1)
v |= BITMASK((b-1)-i);
else
v &= ~BITMASK((b-1)-i);
t>>=1;
}
return v;
}