44 encode(plainText:
string =
"", key:
string =
""):
string {
48 const keyNums = this.sanitize(key)
50 .map(ch => Number(poly.encode(ch).replace(/\s/g,
"")));
53 const plainNums = this.sanitize(plainText)
55 .map(ch => Number(poly.encode(ch).replace(/\s/g,
"")));
58 const encodedNums = plainNums.map((num, i) => num + keyNums[i % keyNums.length]);
60 return encodedNums.join(
" ");
71 decode(cipherText:
string =
"", key:
string =
""):
string {
75 const keyNums = this.sanitize(key)
77 .map(ch => Number(poly.encode(ch).replace(/\s/g,
"")));
80 const cipherNums = cipherText.split(
" ").map(n => Number(n));
83 const letters = cipherNums.map((num, i) => {
84 const val = num - keyNums[i % keyNums.length];
85 return poly.decode(String(val));
88 return letters.join(
"");