44 encode(plainText:
string =
"", key:
string =
""):
string {
45 const numericKey = key.replace(/[^0-9]/g,
'');
47 throw new Error(
'Numeric key required');
51 return plainText.split(
'').map(ch => {
53 if (charIndex === -1) {
57 const shift = Number(numericKey[keyIndex % numericKey.length]);
72 decode(cipherText:
string =
"", key:
string =
""):
string {
73 const numericKey = key.replace(/[^0-9]/g,
'');
75 throw new Error(
'Numeric key required');
79 return cipherText.split(
'').map(ch => {
81 if (charIndex === -1) {
85 const shift = Number(numericKey[keyIndex % numericKey.length]);