mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-25 01:06:16 -04:00
Throws error if modInv didn't work
This commit is contained in:
parent
7bef120a0a
commit
41585e0d3d
1 changed files with 6 additions and 2 deletions
|
@ -166,9 +166,13 @@ export function affineEncrypt(input, a, b, alphabet="a-z") {
|
|||
*/
|
||||
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;
|
||||
return affineApplication(input, aInv, bInv, alphabet, decryptFn);
|
||||
if (aInv === undefined)
|
||||
throw new OperationError("The value of `a` (" + a + ") must be coprime to " + m + ".");
|
||||
else return affineApplication(input, aInv, bInv, alphabet, decryptFn);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,7 +230,7 @@ export const AFFINE_ALPHABETS = [
|
|||
{name: "Letters, match case: a-z", value: "a-z"},
|
||||
{name: "Letters, case sensitive: A-Za-z", value: "A-Za-z"},
|
||||
{name: "Word characters: A-Za-z0-9_", value: "A-Za-z0-9_"},
|
||||
{name: "Printable ASCII: sp-~", value: " -~"}
|
||||
{name: "Printable ASCII: space-~", value: "\\u0020-~"}
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue