c - Write a function (containg bitwise operations) in lua -


i have following alogorithm , want implment in lua. m locking how implement bitwise operations in lua.

void wepkey64(char *passphrase, unsigned char k64[4][5]) {     unsigned char pseed[4] = {0};     unsigned int randnumber, tmp;     int i, j;      for(i = 0; < strlen(passphrase); i++)     {         pseed[i%4] ^= (unsigned char) passphrase[i];     }      randnumber = pseed[0] | (pseed[1] << 8) | (pseed[2] << 16) | (pseed[3] << 24);      (i = 0; < 4; i++)     {         (j = 0; j < 5; j++)         {             randnumber = (randnumber * 0x343fd + 0x269ec3) & 0xffffffff;             tmp = (randnumber >> 16) & 0xff;             k64[i][j] = (unsigned char) tmp;         }     } } 

what's equivalent of function in lua scipting? bitwise operations

recent versions of lua support http://www.lua.org/manual/5.2/manual.html#6.7, if stuck on older version:

randnumber = pseed[0] | (pseed[1] << 8) | (pseed[2] << 16) | (pseed[3] << 24); equivalet of pseed[0] + (pseed[1] * 256) + (pseed[2] * 65536) + (pseed[3] * 16777216)

tmp = (randnumber >> 16) & 0xff; equivalent of (randnumber / 65536) % 0x100 (that integer div , modulus operations)

randnumber = (randnumber * 0x343fd + 0x269ec3) & 0xffffffff; `(randnumber * 0x343fd + 0x269ec3) % 0x100000000;

xor (^) can implemented a^b=a+b-2(a&b)


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -