|
@@ -2399,78 +2399,6 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show)
|
|
|
HWND hWnd;
|
|
|
MSG msg;
|
|
|
|
|
|
- int i;
|
|
|
- int dataLen = 4;
|
|
|
- char data[256] = {0};
|
|
|
- char masked_data[256] = {0};
|
|
|
- uint32_t masking_key = 0x01020304;
|
|
|
-
|
|
|
- for (i = 0; i < dataLen - 3; i += 4) {
|
|
|
- *(uint32_t *)(void *)(masked_data + i) =
|
|
|
- *(uint32_t *)(void *)(data + i) ^ masking_key;
|
|
|
- }
|
|
|
- if (i != dataLen) {
|
|
|
- /* convert 1-3 remaining bytes */
|
|
|
- i -= 4;
|
|
|
- while (i < dataLen) {
|
|
|
- *(uint8_t *)(void *)(masked_data + i) =
|
|
|
- *(uint8_t *)(void *)(data + i)
|
|
|
- ^ *(((uint8_t *)&masking_key) + (i % 4));
|
|
|
- i++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-#if 0
|
|
|
- /* http://lomont.org/Math/Papers/2008/Lomont_PRNG_2008.pdf */
|
|
|
- /* initialize state to random bits
|
|
|
- */
|
|
|
- static unsigned long state[16];
|
|
|
- /* init should also reset this to 0 */
|
|
|
- static unsigned int index = 0;
|
|
|
- /* return 32 bit random number
|
|
|
- */
|
|
|
- unsigned long WELLRN G512(void)
|
|
|
- {
|
|
|
- unsigned long a, b, c, d;
|
|
|
- a = state[index];
|
|
|
- c = state[(index + 13) & 15];
|
|
|
- b = a ^ c ^ (a << 16) ^ (c << 15);
|
|
|
- c = state[(index + 9) & 15];
|
|
|
- c ^= (c >> 11);
|
|
|
- a = state[index] = b ^ c;
|
|
|
- d = a ^ ((a << 5) & 0xDA442D24 UL);
|
|
|
- index = (index + 15) & 15;
|
|
|
- a = state[index];
|
|
|
- state[index] = a ^ b ^ d ^ (a << 2) ^ (b << 18) ^ (c << 28);
|
|
|
- return state[index];
|
|
|
- }
|
|
|
-
|
|
|
- uint32_t x, y, z, w;
|
|
|
-
|
|
|
- uint32_t xorshift128(void)
|
|
|
- {
|
|
|
- uint32_t t = x ^ (x << 11);
|
|
|
- x = y;
|
|
|
- y = z;
|
|
|
- z = w;
|
|
|
- return w = w ^ (w >> 19) ^ t ^ (t >> 8);
|
|
|
- }
|
|
|
-
|
|
|
- static uint64_t lfsr = 1;
|
|
|
- static uint64_t lcg = 0;
|
|
|
- uint64_t r = 0;
|
|
|
-
|
|
|
- do {
|
|
|
- lfsr = (lfsr >> 1)
|
|
|
- | ((((lfsr >> 0) ^ (lfsr >> 1) ^ (lfsr >> 3) ^ (lfsr >> 4)) & 1)
|
|
|
- << 63);
|
|
|
- lcg = lcg * 6364136223846793005 + 1442695040888963407;
|
|
|
- ++r;
|
|
|
- } while (lcg != 0);
|
|
|
-
|
|
|
- fprintf(stdout, "lfsr = %I64u, lcg = %i64u, r = %i64u\n", lfsr, lcg, r);
|
|
|
-#endif
|
|
|
-
|
|
|
(void)hInst;
|
|
|
(void)hPrev;
|
|
|
(void)cmdline;
|