Giter Club home page Giter Club logo

node-fpe's People

Contributors

bschoening avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-fpe's Issues

Fails when radix is larger than approx 20

Larger radix values are currently failing with a primitive number issue. Radix is the size of the alphabet used, so numerics (0..9) is Radix 10 and mono-case English would be Radix 26. It fails with Radix is 20 or more due to overflow.

JavaScript represents all numbers in double precision floating point and has a range of +/- 2^53 for the mantissa. For example,

> Math.pow(2, 53)        // OK
9007199254740992
> Math.pow(2, 53) + 1  // not OK
9007199254740992

The solution is to use BigNum. For this, the Math.pow function needs to be implemented directly as a function instead of using the math library using numbers. I tried a recursive version, but that blew the stack. So, a simple loop is likely what's needed.

Or perhaps we can use the ** operator:

2n**63n-1n
9223372036854775807n

See also:

BigInt do not work compatible with big-integer polyfill

Hi, I tried to make the library compatible with the browser environment, and since BigInt only works on iOS14+, I used the big-integer library(https://www.npmjs.com/package/big-integer) as a polyfill.

I modified the following in FF3Cipher.js to support running scripts:

add require:
const BigInt = require("big-integer");
change line 45:
0n => BigInt(0)
change line 258&367:
let y = BigInt("0x" + s.tostring("hex")); => let y = BigInt(s.tostring("hex"), 16);

However, when the test script was executed, the actual result did not match the expected result.

not ok 9 should be strictly equal
  ---
    operator: equal
    expected: '869304086633418279'
    actual:   '750918814058654607'
    at: Test.<anonymous> (/GitHub/node-fpe/test/FF3CipherTest.js:50:5)
    stack: |-
      Error: should be strictly equal

I tried to modify some other places, but the problem could not be solved. Could you please help to fix the problem?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.