MediaWiki master
|
A mapping which converts sequential input into an output sequence that looks pseudo-random, but preserves the base-10 length of the input number. More...
Inherits MediaWiki\User\TempUser\SerialMapping.
Public Member Functions | |
__construct ( $config) | |
getSerialIdForIndex (int $index) | |
A mapping which converts sequential input into an output sequence that looks pseudo-random, but preserves the base-10 length of the input number.
Take a sequence generated by multiplying the previous element of the sequence by a fixed number "g", then applying the modulus "p":
X(0) = 1 X(i) = ( g X(i-1) ) mod p
If g is a primitive root modulo p, then this sequence will cover all values from 1 to p-1 before it repeats. X(i) is a modular exponential function (g^i mod p) and algorithms are available to calculate it efficiently.
Loosely speaking, we choose a sequence based on the number of digits N in the input, with the period being approximately 10^N, so that the number of digits in the output will be approximately the same.
More precisely, after offsetting the subsequent sequences to avoid colliding with the previous sequences, the period ends up being about 0.9 * 10^N
The modulo p is always a prime number because that makes the maths easier. We use a value for g close to p/sqrt(3) since that seems to stir the digits better than the largest or smallest primitive root.
Definition at line 36 of file ScrambleMapping.php.
MediaWiki\User\TempUser\ScrambleMapping::__construct | ( | $config | ) |
Definition at line 69 of file ScrambleMapping.php.
MediaWiki\User\TempUser\ScrambleMapping::getSerialIdForIndex | ( | int | $index | ) |
int | $index |
Implements MediaWiki\User\TempUser\SerialMapping.
Definition at line 78 of file ScrambleMapping.php.