X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/59f726c989e93a7a29fd23a442bd173839bfc845..713045f81987cf7ac746561b09e607028204bb6c:/client/util.c diff --git a/client/util.c b/client/util.c index 374ae397..60054b94 100644 --- a/client/util.c +++ b/client/util.c @@ -8,6 +8,7 @@ // utilities //----------------------------------------------------------------------------- +#include #include "util.h" #define MAX_BIN_BREAK_LENGTH (3072+384+1) @@ -244,6 +245,15 @@ void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest) { } } +// Swap bit order on a uint32_t value. Can be limited by nrbits just use say 8bits reversal +// And clears the rest of the bits. +uint32_t SwapBits(uint32_t value, int nrbits) { + uint32_t newvalue = 0; + for(int i = 0; i < nrbits; i++) { + newvalue ^= ((value >> i) & 1) << (nrbits - 1 - i); + } + return newvalue; +} // aa,bb,cc,dd,ee,ff,gg,hh, ii,jj,kk,ll,mm,nn,oo,pp // to @@ -581,3 +591,12 @@ void rol(uint8_t *data, const size_t len){ } data[len-1] = first; } + + +// Replace unprintable characters with a dot in char buffer +void clean_ascii(unsigned char *buf, size_t len) { + for (size_t i = 0; i < len; i++) { + if (!isprint(buf[i])) + buf[i] = '.'; + } +}