Skip to content

Commit 6e8c759

Browse files
authored
Merge pull request #1788 from EvieHarv/master
2 parents a429902 + 00f7914 commit 6e8c759

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/core/lib/Ciphers.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
*
44
* @author Matt C [[email protected]]
55
* @author n1474335 [[email protected]]
6+
* @author Evie H [[email protected]]
67
*
78
* @copyright Crown Copyright 2018
89
* @license Apache-2.0
910
*
1011
*/
1112

1213
import OperationError from "../errors/OperationError.mjs";
14+
import Utils from "../Utils.mjs";
1315
import CryptoJS from "crypto-js";
1416

1517
/**
@@ -30,6 +32,10 @@ export function affineEncode(input, args) {
3032
throw new OperationError("The values of a and b can only be integers.");
3133
}
3234

35+
if (Utils.gcd(a, 26) !== 1) {
36+
throw new OperationError("The value of `a` must be coprime to 26.");
37+
}
38+
3339
for (let i = 0; i < input.length; i++) {
3440
if (alphabet.indexOf(input[i]) >= 0) {
3541
// Uses the affine function ax+b % m = y (where m is length of the alphabet)

tests/browser/02_ops.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = {
3737
testOp(browser, ["From Hex", "Add Text To Image", "To Base64"], Images.PNG_HEX, Images.PNG_CHEF_B64, [[], ["Chef", "Center", "Middle", 0, 0, 16], []]);
3838
testOp(browser, "Adler-32 Checksum", "test input", "16160411");
3939
testOp(browser, "Affine Cipher Decode", "test input", "rcqr glnsr", [1, 2]);
40-
testOp(browser, "Affine Cipher Encode", "test input", "njln rbfpn", [2, 1]);
40+
testOp(browser, "Affine Cipher Encode", "test input", "gndg zoujg", [3, 1]);
4141
testOp(browser, "AMF Decode", "\u000A\u0013\u0001\u0003a\u0006\u0009test", /"\$value": "test"/);
4242
testOp(browser, "AMF Encode", '{"a": "test"}', "\u000A\u0013\u0001\u0003a\u0006\u0009test");
4343
testOp(browser, "Analyse hash", "0123456789abcdef", /CRC-64/);

0 commit comments

Comments
 (0)