]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/util.c
CHG: had to move the SwapBits method.
[proxmark3-svn] / client / util.c
index de6443cfcd7ab48a3c927c91b6f884f32ad3171d..fcda9bde0ae7815bf46d1e2c0567c564f43cb526 100644 (file)
@@ -21,14 +21,14 @@ int ukbhit(void)
   int error;
   static struct termios Otty, Ntty;
 
-  tcgetattr( 0, &Otty);
+  if ( tcgetattr( 0, &Otty) == -1) return -1;
   Ntty = Otty;
 
-  Ntty.c_iflag          = 0;       /* input mode                */
-  Ntty.c_oflag          = 0;       /* output mode               */
-  Ntty.c_lflag         &= ~ICANON; /* raw mode */
-  Ntty.c_cc[VMIN]       = CMIN;    /* minimum time to wait      */
-  Ntty.c_cc[VTIME]      = CTIME;   /* minimum characters to wait for */
+  Ntty.c_iflag         = 0;       /* input mode                */
+  Ntty.c_oflag         = 0;       /* output mode               */
+  Ntty.c_lflag         &= ~ICANON; /* raw mode */
+  Ntty.c_cc[VMIN]      = CMIN;    /* minimum time to wait      */
+  Ntty.c_cc[VTIME]     = CTIME;   /* minimum characters to wait for */
 
   if (0 == (error = tcsetattr(0, TCSANOW, &Ntty))) {
     error += ioctl(0, FIONREAD, &cnt);
@@ -503,10 +503,18 @@ uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits) {
 
 // RotateLeft - Ultralight, Desfire, works on byte level
 // 00-01-02  >> 01-02-00
-void rol(uint8_t *data, const size_t len){
+void rol(uint8_t *data, const size_t len){     
     uint8_t first = data[0];
     for (size_t i = 0; i < len-1; i++) {
         data[i] = data[i+1];
     }
     data[len-1] = first;
+}
+
+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;
 }
\ No newline at end of file
Impressum, Datenschutz