X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/4ccdc189bdf814137a8023397f7bf89b707b0465..3e134b4c20a5528b8264cd87d3fdebd0b2df6fd9:/client/util.c diff --git a/client/util.c b/client/util.c index 4bbc992e..4129daaf 100644 --- a/client/util.c +++ b/client/util.c @@ -9,15 +9,13 @@ //----------------------------------------------------------------------------- #include "util.h" -#include "proxmark3.h" #define MAX_BIN_BREAK_LENGTH (3072+384+1) #ifndef _WIN32 #include #include -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; -} \ No newline at end of file +} +/* + 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; +}