mirror of
https://github.com/wiire-a/pixiewps.git
synced 2025-07-27 15:54:29 +02:00
Added another comment on the modulo trick
This commit is contained in:
parent
c44ce9e923
commit
b0b7dbb888
@ -31,10 +31,12 @@ static inline uint32_t *glibc_fast_nonce(uint32_t seed, uint32_t *dest)
|
|||||||
|
|
||||||
/* This does: seed = (16807LL * seed) % 0x7fffffff
|
/* This does: seed = (16807LL * seed) % 0x7fffffff
|
||||||
using the sum of digits method which works for mod N, base N+1 */
|
using the sum of digits method which works for mod N, base N+1 */
|
||||||
/* Doesn't work for seed = 0x7fffffff or 0xfffffffe */
|
|
||||||
uint64_t p = 16807ULL * seed;
|
uint64_t p = 16807ULL * seed;
|
||||||
p = (p >> 31) + (p & 0x7fffffff);
|
p = (p >> 31) + (p & 0x7fffffff);
|
||||||
seed = (p >> 31) + (p & 0x7fffffff);
|
seed = (p >> 31) + (p & 0x7fffffff);
|
||||||
|
#if 0 /* Same as PWPS_UNERRING */
|
||||||
|
if (seed == 0x7fffffff) seed = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
dest[0] = word0 >> 1;
|
dest[0] = word0 >> 1;
|
||||||
dest[1] = word1 >> 1;
|
dest[1] = word1 >> 1;
|
||||||
@ -57,10 +59,12 @@ static inline uint32_t glibc_fast_seed(uint32_t seed)
|
|||||||
|
|
||||||
/* This does: seed = (16807LL * seed) % 0x7fffffff
|
/* This does: seed = (16807LL * seed) % 0x7fffffff
|
||||||
using the sum of digits method which works for mod N, base N+1 */
|
using the sum of digits method which works for mod N, base N+1 */
|
||||||
/* Doesn't work for seed = 0x7fffffff or 0xfffffffe */
|
|
||||||
uint64_t p = 16807ULL * seed;
|
uint64_t p = 16807ULL * seed;
|
||||||
p = (p >> 31) + (p & 0x7fffffff);
|
p = (p >> 31) + (p & 0x7fffffff);
|
||||||
seed = (p >> 31) + (p & 0x7fffffff);
|
seed = (p >> 31) + (p & 0x7fffffff);
|
||||||
|
#if 0 /* Same as PWPS_UNERRING */
|
||||||
|
if (seed == 0x7fffffff) seed = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return (word0 + seed * glibc_seed_tbl[33]) >> 1;
|
return (word0 + seed * glibc_seed_tbl[33]) >> 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user