Converts an integer to another integer that is unpredictable and reversible.
npm install @japan-d2/scrambler
or
yarn add @japan-d2/scrambler
- Decide the number of digits (ex. 4)
- Decide one first odd number (n1) that fits in the number of digits (ex. 1101)
- Formulate
1101x - (10^4)y = 1
- Enter the formula into Wolfram|Alpha and get an integer solution
x = 10000 n + 8901, y = 1101 n + 980, n element Z
- Get the second odd number (n2)
8901
import { createScrambler } from '@japan-d2/scrambler'
const scrambler = createScrambler({
digits: 4,
n1: BigInt(1101),
n2: BigInt(8901),
seed: 123456789,
stages: 10
})
const from = BigInt(1)
const to = scrambler.scramble(from)
const restored = scrambler.restore(to)
console.log({
from,
to,
restored
})
{
from: 1n,
to: 4055n,
restored: 1n
}
Return the scrambler.
number of digits in space.
Odd number pair that satisfies (n1 * n2) % (10 ** digits) === 1
.
Seed value for swap table creation.
Number of swap/slide stages.
MIT