What is this used for?
|
Has this been written before?Code:private static int mix32(int v) { int a = v & 0xff; int b = (v >>> 8) & 0xff; int c = (v >>> 16) & 0xff; int d = v >>> 24; //AUTHOR: JOSEPH R. MELSHA int A = a + b; int B = b + c; int C = c + d; int D = d + a; a += C; b += D; c += A; d += B; return (a << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff); }
What is this used for?
looks secure to me.
To me it seems you can't reverse this as you're summing up the values of 3 bytes together into an integer value, most probably overflowing the first 8 bits into the rest of the bits, and after that you cut of 24 bits and keep the last 8 bits cutting away a maximum of 16 significant bits:
You loose bits so you can't say what's inside the 4 bytes that are created to construct the mixed 32 bit integer.Code:a = ((v & 0xff) + ((v >>> 16) & 0xff) + (v >>> 24)) & 0xff
You know the following about your method. Each byte is repeated exactly 3 times across the whole mixing process. Values are combined by simple addition. As a result, when reading you can do.
Which is equal to the sum of all the initial bytes in the encryption methodCode:int value = (a + b + c + d) / 3;
At this point, it should be relatively simple to get the individual initial bytes by subtracting the numbers, since the value quantity is composed of all 4 bytes whereas each of the read bytes is only 3 of them.Code:int first = value - a; int second = value - b; int third = value - c; int fourth = value - d;
Note: The naming is based around your convention of a, b, c,d. Ofc you will need to split up the encrypted number into bytes again. Additionally, with larger numbers there will be a loss of data. I cbf really at hypothesizing what that would be approximately.
the cool thing about this function is that it has no collisions.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |