Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decryption wrong if format() is less than firstFactor #6

Open
sparecycles opened this issue Nov 2, 2020 · 0 comments
Open

Decryption wrong if format() is less than firstFactor #6

sparecycles opened this issue Nov 2, 2020 · 0 comments

Comments

@sparecycles
Copy link

sparecycles commented Nov 2, 2020

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant