CyberChef icon indicating copy to clipboard operation
CyberChef copied to clipboard

Fix: Support negative parameters in Affine Cipher operations

Open ThanatosXingYu opened this issue 3 months ago • 1 comments

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)

ThanatosXingYu avatar Oct 03 '25 09:10 ThanatosXingYu

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Oct 03 '25 09:10 CLAassistant