Log in

View Full Version : (x<<13) | (x>>3)


mkfeldman
December 23rd, 2007, 17:20
Happy Christmas everybody,
I'm reversing a licensing system and almost solved everything (I can generate the correct key for any valid serial number) but I wanted to reverse the serial number validation (to be able to generate valid serials, as the cherry on the cake) and this turned out the be the most intricate of all.
At some stage the code uses the following algorithm to make a 32 bit hash of a c-string:

with s pointing to the string to hash:

hash=0
while (*s) {
hash = mix(hash,*s)
s++
}

my problem is with mix, it does this:

return Sbox[arg1 ^ arg0] ^ (arg1 >>3 | arg1 << 13)

Although I can simulate the mechanism at will, I got intrigued by this >>3 <<13, I searched in google code and I saw it used in RC2 code and also in some other strange malloc code but found nothing that explains what (x/8 + x*8192) is useful for!
http://www.google.com/codesearch?hl=en&q=+%3C%3C13+%3E%3E3&sa=N

Have anyone seen this before?
thnks

dELTA
December 23rd, 2007, 18:40
That would be a highly common/normal bit rotation three steps to the right, simulated by two bit shift operations. You should not see it as an arithmetic operation, so don't worry about the mathematical formulas for it.

mkfeldman
December 23rd, 2007, 19:03
yes a barrel shift! thanks