mysto / node-fpe Goto Github PK
View Code? Open in Web Editor NEWFPE - Format Preserving Encryption with FF3 in Node-js
Home Page: https://privacylogistics.com
License: Apache License 2.0
FPE - Format Preserving Encryption with FF3 in Node-js
Home Page: https://privacylogistics.com
License: Apache License 2.0
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:
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.