Skip to content

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

@sparecycles

Description

@sparecycles

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions