mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 23:06:16 -04:00
Uses new Utils.modInv function
This commit is contained in:
parent
cb6b1f7509
commit
7ae35bc587
1 changed files with 3 additions and 2 deletions
|
@ -86,7 +86,7 @@ export function affineApplication(input, a, b, alphabet, affineFn) {
|
|||
}
|
||||
|
||||
if (Utils.gcd(a, modulus) !== 1) {
|
||||
throw new OperationError("The value of `a` must be coprime to " + modulus + ".");
|
||||
throw new OperationError("The value of `a` (" + a + ") must be coprime to " + modulus + ".");
|
||||
}
|
||||
|
||||
// Apply affine function to each character in the input
|
||||
|
@ -168,9 +168,10 @@ export function affineDecrypt(input, a, b, alphabet="a-z") {
|
|||
const m = Utils.expandAlphRange(alphabet).length;
|
||||
if (Utils.gcd(a, m) !== 1)
|
||||
throw new OperationError("The value of `a` (" + a + ") must be coprime to " + m + ".");
|
||||
|
||||
const aInv = Utils.modInv(a, m);
|
||||
const bInv = (m - b) % m;
|
||||
if (aInv === undefined)
|
||||
if (aInv === null)
|
||||
throw new OperationError("The value of `a` (" + a + ") must be coprime to " + m + ".");
|
||||
else return affineApplication(input, aInv, bInv, alphabet, decryptFn);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue