Skip to content

Conversation

ThanatosXingYu
Copy link

Problem

The Affine Cipher encrypt/decrypt operations were restricted to positive integers only for parameters a and b, preventing correct decryption of ciphertexts that require negative parameters.

Example:

  • Input: szzyfimhyzd
  • Parameters: a=17, b=-8
  • Expected output: affineshift
  • Actual output: Error ”a and b must be integers“

Solution

Modified the parameter validation regex in src\core\lib\Ciphers.mjs:31 to accept both positive and negative integers:

Before:

if (!/^\+?(0|[1-9]\d*)$/.test(a) || !/^\+?(0|[1-9]\d*)$/.test(b)) {

After:

if (!/^[+-]?(0|[1-9]\d*)$/.test(a) || !/^[+-]?(0|[1-9]\d*)$/.test(b)) {

And maintains all existing mathematical constraints (gcd(a,26)=1)

@CLAassistant
Copy link

CLAassistant commented Oct 3, 2025

CLA assistant check
All committers have signed the CLA.

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

Successfully merging this pull request may close these issues.

2 participants