The calculation of left in decryption can result in a negative number when modulu is less than 0,
|
left = (modulu > 0) ? firstFactor - modulu : modulu; |
this leads to a failure to recover the original value.
The value produced should be based on - modulu in all cases (to ensure a positive result):
left = (modulu > 0) ? firstFactor - modulu : - modulu;
You can confirm this change is an improvement by
- first removing all
expectedEV assertions from the unit tests (tests should still pass with less assertions)
- modifying the
format() function to return ... % 100n to force the modulu <= 0 case to occur, (tests now fail).
- then updating the code as above. (tests pass again, because the code was fixed).
Then remember to
- restore the current
format() function.
- restore the current test code (all original tests will still pass with all assertions).
The calculation of
leftin decryption can result in a negative number whenmoduluis less than 0,node-fe1-fpe/index.js
Line 63 in ceae15b
this leads to a failure to recover the original value.
The value produced should be based on
- moduluin all cases (to ensure a positive result):You can confirm this change is an improvement by
expectedEVassertions from the unit tests (tests should still pass with less assertions)format()function toreturn ... % 100nto force themodulu <= 0case to occur, (tests now fail).Then remember to
format()function.