cipher-collection
Version:
Zero-dependency modular cipher collection including all well-known and often used ciphers
896 lines (728 loc) • 24.9 kB
JavaScript
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var defineProperty = function (obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
};
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
var slicedToArray = function () {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
return function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
return sliceIterator(arr, i);
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
};
}();
var toConsumableArray = function (arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
return arr2;
} else {
return Array.from(arr);
}
};
// min <= x < max
var randomInRange = function randomInRange(min, max) {
if (min > max) {
throw Error('Min cannot be larger than max');
}
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
};
var throwOrSilent = function throwOrSilent(options, errorMessage) {
if (options.failOnUnknownCharacter) {
throw Error(errorMessage);
}
return '';
};
var isBrowser = function () {
return (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object';
}();
/**
* Calculates the modular inverse of an arbitrary input number and modulo
* @param number The number the inverse should be calculated for
* @param mod the modulo parameter
* @returns {number|boolean} Either the corresponding mod inverse number, or false if it does not exist
*/
var modInverse = function modInverse(number, mod) {
if (number < 0 || mod < 2) {
throw Error('Invalid input');
}
// Ensure that the number is in scope
number = number % mod;
// Create an array of possible solutions (1 < x < mod)
var rangeArray = Array.from(new Array(mod - 1), function (x, i) {
return i + 1;
});
// Now find the mod inverse number or return false. Mod inverse: (i * number = 1) % mod
return rangeArray.find(function (i) {
return i * number % mod === 1;
}) % mod || false;
};
var rotateAndMultiply = function rotateAndMultiply(c, options) {
options = _extends({}, DEFAULT_ROTATE_AND_MULTIPLY_OPTIONS, options);
var type = getType(c);
return type === ROTATE_AND_MULTIPLY_TYPES.OTHER || !isAllowed(type, options.types) ? throwOrSilent(options, options.errorMessage) || options.omitUnknownCharacter ? '' : c : modifyCharacter(c, { type: type, keys: options.keys, decode: options.decode });
};
var isAllowed = function isAllowed(characterType, allowedTypes) {
if (allowedTypes === true) {
return true;
}
var bitmask = allowedTypes.reduce(function (acc, type) {
return acc | type;
});
return !!(bitmask & characterType);
};
var modifyCharacter = function modifyCharacter(c, options) {
var asciiOfset = ROTATE_AND_MULTIPLY_ASCII[options.type];
var parsedCharacter = parseInt(c, 36) - (options.type === ROTATE_AND_MULTIPLY_TYPES.NUMBER ? 0 : 10);
var mod = options.type === ROTATE_AND_MULTIPLY_TYPES.NUMBER ? 10 : 26;
var multiplicationKey = options.decode ? modInverse(options.keys[0], mod) : options.keys[0];
var additionKey = options.keys[1];
// Depending on en- or decoding, change transformation formula
var transformedCode = options.decode ? multiplicationKey * (parsedCharacter - additionKey) : parsedCharacter * multiplicationKey + additionKey;
// Recreate "real modulo" by handling negative values
while (transformedCode < 0) {
transformedCode += mod;
}
return String.fromCharCode(asciiOfset + transformedCode % mod);
};
var DEFAULT_ROTATE_AND_MULTIPLY_OPTIONS = {
keys: [3, 0],
types: true,
failOnUnknownCharacter: true,
omitUnknownCharacter: false,
decode: false
};
var getType = function getType(c) {
return c >= 'a' && c <= 'z' ? ROTATE_AND_MULTIPLY_TYPES.LOWERCASE : c >= 'A' && c <= 'Z' ? ROTATE_AND_MULTIPLY_TYPES.UPPERCASE : c >= '0' && c <= '9' ? ROTATE_AND_MULTIPLY_TYPES.NUMBER : ROTATE_AND_MULTIPLY_TYPES.OTHER;
};
var ROTATE_AND_MULTIPLY_TYPES = {
UPPERCASE: 1,
LOWERCASE: 2,
NUMBER: 4,
OTHER: 8
};
var ROTATE_AND_MULTIPLY_ASCII = {
1: 65,
2: 97,
4: 48
};
/**
* The well-known Caesar or ROT (for rotations) cipher. It'll rotate letters (and optionally numbers) by 13 or a
* custom number of rotations. Only numbers and ASCII letters will be transformed. other characters (including
* special characters, umlauts like äüä or other variants) will stay the same. This function is case-sensitive.
*
* @since 0.0.1
*
* @param {string|function} input - The input that should be rotated
* @param {object} options - Option object
* @returns {string} rotated input
* @example
*
* const input = 'ABC'
* rot(input) // NOP
*/
var rot = (function (input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS, options);
return [].concat(toConsumableArray(input)).map(function (c) {
return rotateAndMultiply(c, getConfig(options));
}).join('');
});
var getConfig = function getConfig(options) {
return {
types: options.rotateNumbers ? true : [ROTATE_AND_MULTIPLY_TYPES.LOWERCASE, ROTATE_AND_MULTIPLY_TYPES.UPPERCASE, ROTATE_AND_MULTIPLY_TYPES.OTHER],
keys: [1, options.rotations % 26],
failOnUnknownCharacter: false
};
};
var DEFAULT_OPTIONS = {
rotateNumbers: false,
rotations: 13
};
var decode = function decode(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$1, options);
return input.split(options.separator).map(function (c) {
var decodedCharacter = Object.entries(ALPHABET).find(function (_ref) {
var _ref2 = slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return v === c;
});
if (decodedCharacter) {
return decodedCharacter[0];
}
throwOrSilent(options, 'Undecodable character ' + c);
return options.omitUnknownCharacter ? '' : c;
}).join('');
};
var encode = function encode(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$1, options);
return [].concat(toConsumableArray(input.toUpperCase())).map(function (c) {
var encodedCharacter = Object.entries(ALPHABET).find(function (_ref3) {
var _ref4 = slicedToArray(_ref3, 1),
k = _ref4[0];
return k === c;
});
if (encodedCharacter) {
return encodedCharacter[1];
}
throwOrSilent(options, 'Unencodable character ' + c);
return options.omitUnknownCharacter ? '' : c;
}).join(options.separator);
};
var ALPHABET = {
A: '.-',
B: '-...',
C: '-.-.',
D: '-..',
E: '.',
F: '..-.',
G: '--.',
H: '....',
I: '..',
J: '.---',
K: '-.-',
L: '.-..',
M: '--',
N: '-.',
O: '---',
P: '.--.',
Q: '--.-',
R: '.-.',
S: '...',
T: '-',
U: '..-',
V: '...-',
W: '.--',
X: '-..-',
Y: '-.--',
Z: '--..',
1: '.----',
2: '..---',
3: '...--',
4: '....-',
5: '.....',
6: '-....',
7: '--...',
8: '---..',
9: '----.',
0: '-----',
' ': '/',
'.': '.-.-.-',
',': '--..--',
':': '---...',
';': '-.-.-.',
'?': '..--..',
'-': '-....-',
'_': '..--.-',
'(': '-.--.',
')': '-.--.-',
'\'': '.----.',
'=': '-...-',
'+': '.-.-.',
'/': '-..-.',
'@': '.--.-.'
};
var DEFAULT_OPTIONS$1 = {
separator: ' ',
failOnUnknownCharacter: true,
omitUnknownCharacter: false
};
var morse = {
decode: decode,
encode: encode
};
var decode$1 = function decode$$1(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$2, options);
var morseOptions = _extends({}, DEFAULT_MORSE_OPTION, { failOnUnknownCharacter: options.failOnUnknownCharacter });
var morseCode = [].concat(toConsumableArray(input)).map(function (c) {
var decodedCharacterIndex = options.keyAlphabet.indexOf(c);
if (decodedCharacterIndex !== -1) {
return ENCODED_ALPHABET[decodedCharacterIndex];
}
return throwOrSilent(options, 'Undecodable character ' + c);
}).join('')
// Remove padding if needed
.replace(/x{1,2}$/, '')
// Fix unwanted space encoding
.replace(/xx/g, SPACE_STRING);
return morse.decode(morseCode, morseOptions);
};
var encode$1 = function encode$$1(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$2, options);
var morseOptions = _extends({}, DEFAULT_MORSE_OPTION, { failOnUnknownCharacter: options.failOnUnknownCharacter });
return morseCodeFromInput(input, morseOptions)
// Split into arrays containing three-character strings
.match(/.{3}/g).map(function (c) {
var encodedCharacterIndex = ENCODED_ALPHABET.indexOf(c);
if (encodedCharacterIndex !== -1) {
return options.keyAlphabet[encodedCharacterIndex];
}
return throwOrSilent(options, 'Unencodable character ' + c);
}).join('');
};
var morseCodeFromInput = function morseCodeFromInput(input, morseOptions) {
var morseCode = morse.encode(input.toUpperCase(), morseOptions);
// Add padding if needed
if (morseCode.length % 3) {
morseCode += morseOptions.separator.repeat(3 - morseCode.length % 3);
}
return morseCode.replace(new RegExp('' + morseOptions.separator, 'g'), 'x')
// Fix unwanted space encoding
.replace(new RegExp('' + SPACE_STRING, 'g'), 'xx');
};
var ENCODED_ALPHABET = ['...', '..-', '..x', '.-.', '.--', '.-x', '.x.', '.x-', '.xx', '-..', '-.-', '-.x', '--.', '---', '--x', '-x.', '-x-', '-xx', 'x..', 'x.-', 'x.x', 'x-.', 'x--', 'x-x', 'xx.', 'xx-'];
var SPACE_STRING = 'x/x';
var DEFAULT_OPTIONS$2 = {
keyAlphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
failOnUnknownCharacter: true
};
var DEFAULT_MORSE_OPTION = {
separator: 'x'
};
var fractionatedMorse = {
decode: decode$1,
encode: encode$1
};
/* eslint-disable no-unused-vars */
var decode$2 = function decode$$1(input) {
var keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var morseOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
sanitizeKeys(keys);
input = [].concat(toConsumableArray(input)).map(function (c) {
var decodedCharacter = Object.entries(keys).find(function (_ref) {
var _ref2 = slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return v.includes(c);
});
var morseCode = decodedCharacter ? propToKey(decodedCharacter[0]) : false;
if (!morseCode) {
throw Error('Unknown key ' + c);
}
return morseCode;
}).join('');
return [].concat(toConsumableArray(morse.decode(input, morseOptions))).join('');
};
var encode$2 = function encode$$1(input) {
var keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var morseOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
sanitizeKeys(keys);
return [].concat(toConsumableArray(morse.encode(input.toUpperCase(), morseOptions))).map(function (c) {
var key = keyToProp(c);
if (!key) {
throw Error('Unknown key ' + c);
}
return [].concat(toConsumableArray(keys[key]))[randomInRange(0, keys[key].length)];
}).join('');
};
var keyToProp = function keyToProp(c) {
return c === ' ' ? 'space' : c === '.' ? 'short' : c === '-' ? 'long' : c === '/' ? 'separator' : false;
};
var propToKey = function propToKey(c) {
return c === 'space' ? ' ' : c === 'short' ? '.' : c === 'long' ? '-' : '/';
};
var sanitizeKeys = function sanitizeKeys(keys) {
if (!Object.keys(keys).length) {
throw Error('You have no keys set');
}
var existingKeys = ['space', 'short', 'long', 'separator'];
if (Object.keys(keys).length !== existingKeys.length || Object.keys(keys).filter(function (key) {
return !existingKeys.includes(key);
}).length) {
throw Error('Please define your keys: ' + existingKeys.join(', '));
}
};
var pollux = {
decode: decode$2,
encode: encode$2
};
var encode$3 = function encode(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$3, options);
return [].concat(toConsumableArray(input.toUpperCase())).map(function (c) {
var decodedCharacter = Object.entries(alphabetWithSpaceKey(options.customMapping)).find(function (_ref) {
var _ref2 = slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return v.includes(c);
});
if (decodedCharacter) {
var amount = decodedCharacter[1].indexOf(c) + 1;
return options.exponentForm ? decodedCharacter[0] + '^' + amount : ('' + decodedCharacter[0]).repeat(amount);
}
return throwOrSilent(options, 'Unencodable character ' + c);
}).filter(function (c) {
return c.length;
}).join(options.withSpacing ? ' ' : '');
};
var decode$3 = function decode(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$3, options);
var alphabet = alphabetWithSpaceKey(options.customMapping);
var invalidInputRegex = /[^\d^*# ]/g;
// Validate input
if (input.match(invalidInputRegex)) {
if (options.failOnUnknownCharacter) {
throw Error('Undecodable characters');
} else {
input.replace(invalidInputRegex);
}
}
if (!input.length) {
return '';
}
var capturedInput = options.exponentForm ? input.match(/\d\^\d ?/g) : input.match(/(([79])\2{0,4}|([234568])\3{0,2}|([01*#])\4{0,2}) ?/g);
return capturedInput.map(function (expr) {
expr = expr.replace(/ /g, '');
return options.exponentForm ? alphabet[expr[0]][expr[2] - 1] : alphabet[expr[0]][expr.length - 1];
}).join('');
};
var alphabetWithSpaceKey = function alphabetWithSpaceKey(customMapping) {
return (typeof customMapping === 'undefined' ? 'undefined' : _typeof(customMapping)) === 'object' ? _extends({}, ALPHABET$1, customMapping) : ALPHABET$1;
};
var DEFAULT_OPTIONS$3 = {
customMapping: {
0: ' '
},
exponentForm: false,
withSpacing: true,
failOnUnknownCharacter: true
};
var ALPHABET$1 = {
2: 'ABC',
3: 'DEF',
4: 'GHI',
5: 'JKL',
6: 'MNO',
7: 'PQRS',
8: 'TUV',
9: 'WXYZ'
};
var multiTap = {
decode: decode$3,
encode: encode$3
};
var decode$4 = function decode(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$4, options);
return input.split(options.separator).map(function (i) {
var lookup = getLookup(options.mode);
checkMode(options);
if (options.mode === 'include') {
var foundRow = Object.entries(lookup).find(includesKey(i));
if (!foundRow) {
return throwOrSilent(options, 'Could not decode ' + i + ' - No row found');
}
var foundCell = Object.entries(foundRow[1]).find(includesKey(i));
if (!foundCell) {
return throwOrSilent(options, 'Could not decode ' + i + ' - No cell found');
}
return foundCell[1];
}
if (lookup.hasOwnProperty(i)) {
return lookup[i];
}
return throwOrSilent(options, 'Could not decode ' + i + ' - No matching value');
}).join('');
};
var includesKey = function includesKey(i) {
return function (_ref) {
var _ref2 = slicedToArray(_ref, 1),
key = _ref2[0];
return i.includes(key);
};
};
var getLookup = function getLookup(mode) {
return mode === 'include' ? LOOKUP : Object.entries(LOOKUP).map(function (_ref3) {
var _ref4 = slicedToArray(_ref3, 2),
k = _ref4[0],
rowObj = _ref4[1];
return Object.entries(rowObj).reduce(function (acc, _ref5) {
var _ref6 = slicedToArray(_ref5, 2),
rowK = _ref6[0],
v = _ref6[1];
return _extends({}, acc, defineProperty({}, mode === 'sum' ? Number(rowK) + Number(k) : Number(rowK) - Number(k), v));
}, {});
}).reduce(function (acc, obj) {
return _extends({}, acc, obj);
}, {});
};
var encode$4 = function encode(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$4, options);
checkMode(options);
return [].concat(toConsumableArray(input)).map(function (i) {
var result = Object.entries(LOOKUP).map(function (_ref7) {
var _ref8 = slicedToArray(_ref7, 2),
key = _ref8[0],
freqOb = _ref8[1];
var foundFreq = Object.entries(freqOb).find(function (_ref9) {
var _ref10 = slicedToArray(_ref9, 2),
k = _ref10[0],
v = _ref10[1];
return v === i;
});
if (foundFreq) {
return encodeResult([key, foundFreq[0]], options);
}
return false;
}).find(function (o) {
return o;
});
return !result ? throwOrSilent(options, 'Invalid input') : result;
}).join(options.separator);
};
var encodeResult = function encodeResult(frequencies, _ref11) {
var mode = _ref11.mode,
invertedOutput = _ref11.invertedOutput,
connector = _ref11.connector;
// If output should be inverted, reverse array
if (invertedOutput) {
frequencies.reverse();
}
frequencies = frequencies.map(function (f) {
return Number(f);
});
var resultObjects = {
include: '' + frequencies[0] + connector + frequencies[1],
sum: '' + (frequencies[0] + frequencies[1]),
diff: '' + (frequencies[0] > frequencies[1] ? frequencies[0] - frequencies[1] : frequencies[1] - frequencies[0])
};
return resultObjects[mode];
};
var checkMode = function checkMode(_ref12) {
var mode = _ref12.mode;
if (!TYPES.includes(mode)) {
throw new Error('Unknown mode');
}
};
var TYPES = ['include', 'sum', 'diff'];
var DEFAULT_OPTIONS$4 = {
mode: 'include',
connector: '+',
separator: ' ',
invertedOutput: false,
failOnUnknownCharacter: true
};
var LOOKUP = {
697: { 1209: '1', 1336: '2', 1477: '3', 1633: 'A' },
770: { 1209: '4', 1336: '5', 1477: '6', 1633: 'B' },
852: { 1209: '7', 1336: '8', 1477: '9', 1633: 'C' },
941: { 1209: '*', 1336: '0', 1477: '#', 1633: 'D' }
};
var dtmf = {
decode: decode$4,
encode: encode$4
};
// Courtesy: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
var decode$5 = function decode(input) {
return isBrowser ? decodeURIComponent(atob(input).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join('')) : atob(input);
};
var encode$5 = function encode(input) {
return isBrowser ? btoa(encodeURIComponent(input).replace(/%([0-9A-F]{2})/g, function (match, p1) {
return String.fromCharCode('0x' + p1);
})) : btoa(input);
};
var btoa = isBrowser ? window.btoa : function (i) {
return Buffer.from(i).toString('base64');
};
var atob = isBrowser ? window.atob : function (i) {
return Buffer.from(i, 'base64').toString();
};
var base64 = {
decode: decode$5,
encode: encode$5
};
var substitute = function substitute(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_SUBSTITUTE_OPTIONS, options);
var mappingEntries = Object.entries(options.mapping);
return input.replace(/./g, function (x) {
var transformedEntries = options.caseSensitive ? mappingEntries : mappingEntries.map(function (_ref) {
var _ref2 = slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return isLowerCase(x) ? [k.toLowerCase(), v.toLowerCase()] : [k.toUpperCase(), v.toUpperCase()];
});
var foundMapping = transformedEntries.find(function (_ref3) {
var _ref4 = slicedToArray(_ref3, 2),
k = _ref4[0],
v = _ref4[1];
return k === x || v === x;
});
return !foundMapping ? x : foundMapping[0] === x ? foundMapping[1] : foundMapping[0];
});
};
var isLowerCase = function isLowerCase(x) {
return x.toLowerCase() === x;
};
var DEFAULT_SUBSTITUTE_OPTIONS = {
mapping: {},
caseSensitive: true
};
var wolfenbuetteler = (function (input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return substitute(input, retrieveOptions(options));
});
var retrieveOptions = function retrieveOptions(options) {
return {
mapping: DEFAULT_MAPPING,
caseSensitive: options.onlyUpperCase
};
};
var DEFAULT_MAPPING = {
'A': 'M',
'E': 'K',
'I': 'D',
'O': 'T',
'U': 'H'
};
var encode$6 = function encode(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$5, options);
return transform(input, options);
};
var decode$6 = function decode(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$5, options);
options.decode = true;
return transform(input, options);
};
var transform = function transform(input, options) {
if (!LEGAL_KEYS.includes(options.key)) {
throw new Error('Illegal key');
}
return [].concat(toConsumableArray(input)).map(function (c) {
return rotateAndMultiply(c, getRotateAndMultiplyConfig(options));
}).join('');
};
var DEFAULT_OPTIONS$5 = {
key: 3,
failOnUnknownCharacter: false,
omitUnknownCharacter: false
};
var getRotateAndMultiplyConfig = function getRotateAndMultiplyConfig(options) {
return {
types: [ROTATE_AND_MULTIPLY_TYPES.LOWERCASE, ROTATE_AND_MULTIPLY_TYPES.UPPERCASE],
keys: [options.key, 0],
failOnUnknownCharacter: options.failOnUnknownCharacter,
omitUnknownCharacter: options.omitUnknownCharacter,
errorMessage: 'Could not multiply character',
decode: options.decode
};
};
// Keys that are co-prime to 26 (gcd(a, 26) = 1)
var LEGAL_KEYS = [3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25];
var multiplicative = {
encode: encode$6,
decode: decode$6
};
var encode$7 = function encode(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$6, options);
return transform$1(input, options);
};
var decode$7 = function decode(input) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
options = _extends({}, DEFAULT_OPTIONS$6, options);
options.decode = true;
return transform$1(input, options);
};
var transform$1 = function transform(input, options) {
if (!LEGAL_MULT_KEYS.includes(options.keys[0])) {
throw new Error('Illegal keys');
}
return [].concat(toConsumableArray(input)).map(function (c) {
return rotateAndMultiply(c, getRotateAndMultiplyConfig$1(options));
}).join('');
};
var getRotateAndMultiplyConfig$1 = function getRotateAndMultiplyConfig(options) {
return {
types: [ROTATE_AND_MULTIPLY_TYPES.LOWERCASE, ROTATE_AND_MULTIPLY_TYPES.UPPERCASE],
keys: options.keys,
failOnUnknownCharacter: options.failOnUnknownCharacter,
omitUnknownCharacter: options.omitUnknownCharacter,
errorMessage: 'Could not transform character',
decode: options.decode
};
};
var DEFAULT_OPTIONS$6 = {
keys: [3, 1],
failOnUnknownCharacter: false,
omitUnknownCharacter: false
// Keys that are co-prime to 26 (gcd(a, 26) = 1)
};var LEGAL_MULT_KEYS = [3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25];
var affine = {
encode: encode$7,
decode: decode$7
};
var index = {
rot: rot,
morse: morse,
fractionatedMorse: fractionatedMorse,
pollux: pollux,
multiTap: multiTap,
dtmf: dtmf,
base64: base64,
wolfenbuetteler: wolfenbuetteler,
multiplicative: multiplicative,
affine: affine
};
export default index;