0.0.5 • Published 3 years ago

@japan-d2/scrambler v0.0.5

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

@japan-d2/scrambler

Converts an integer to another integer that is unpredictable and reversible.

install

npm install @japan-d2/scrambler

or

yarn add @japan-d2/scrambler

how to use

find two numbers

  1. Decide the number of digits (ex. 4)
  2. Decide one first odd number (n1) that fits in the number of digits (ex. 1101)
  3. Formulate

1101x - (10^4)y = 1

  1. Enter the formula into Wolfram|Alpha and get an integer solution

x = 10000 n + 8901, y = 1101 n + 980, n element Z

  1. Get the second odd number (n2)

8901

example

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
})

Output

{
  from: 1n,
  to: 4055n,
  restored: 1n
}

methods

createScrambler(options): Scrambler

Return the scrambler.

Options

digits: number

number of digits in space.

n1: number, n2: number

Odd number pair that satisfies (n1 * n2) % (10 ** digits) === 1.

seed: number

Seed value for swap table creation.

stages: number

Number of swap/slide stages.

license

MIT

0.0.5

3 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago