28 private readonly labels = [
'A',
'D',
'F',
'G',
'V',
'X'];
34 private readonly square:
string[];
60 encode(plainText:
string =
'', key:
string =
''):
string {
61 const clean = plainText.toUpperCase();
63 for (
const ch of clean) {
64 const idx = this.square.indexOf(ch);
66 pairs += ch;
continue;
68 const r = Math.floor(idx / 6), c = idx % 6;
69 pairs += this.labels[r] + this.labels[c];
83 decode(ciphertext:
string =
'', key:
string =
''):
string {
84 const pairs = new
ColumnarCipher().decode(ciphertext, key).match(/../g) || [];
86 for (
const p of pairs) {
87 const r = this.labels.indexOf(p[0]);
88 const c = this.labels.indexOf(p[1]);
89 if (r === -1 || c === -1) {
92 out += this.square[r * 6 + c];