CyberChef
CyberChef copied to clipboard
Bug report: Utils.modInv assumes modulus of 26
Describe the bug
The Utils.modInv function internally uses 26 as the modulus rather than the argument y
. The bug is not externally visible because it's used in the Affine Decode operation, which uses an alphabet with 26 letters.
Source code
static modInv(x, y) {
x %= y;
for (let i = 1; i < y; i++) {
if ((x * i) % 26 === 1) {
return i;
}
}
}
Remedy
Replace 26
with y
.
Better still: replace the entire function with one that uses the Extended Euclidean Algorithm to compute the modular multiplicative inverse. It will be faster than a brute-force loop for large values of y
.