mirror of
https://github.com/gchq/CyberChef
synced 2024-11-14 16:47:07 +00:00
Require (a, 26) to be coprime in affine encode
This commit is contained in:
parent
b2e400f474
commit
a09f8451fd
1 changed files with 6 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
*
|
||||
* @author Matt C [matt@artemisbot.uk]
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @author Evie H [evie@evie.sh]
|
||||
*
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
|
@ -10,6 +11,7 @@
|
|||
*/
|
||||
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
import CryptoJS from "crypto-js";
|
||||
|
||||
/**
|
||||
|
@ -30,6 +32,10 @@ export function affineEncode(input, args) {
|
|||
throw new OperationError("The values of a and b can only be integers.");
|
||||
}
|
||||
|
||||
if (Utils.gcd(a, 26) !== 1) {
|
||||
throw new OperationError("The value of `a` must be coprime to 26.");
|
||||
}
|
||||
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
if (alphabet.indexOf(input[i]) >= 0) {
|
||||
// Uses the affine function ax+b % m = y (where m is length of the alphabet)
|
||||
|
|
Loading…
Reference in a new issue