31 static readonly
ALPHABET:
string =
"ABCDEFGHIKLMNOPQRSTUVWXYZ";
48 encode(plaintext:
string):
string {
50 const result:
string[] = [];
52 for (
const ch of plaintext.toUpperCase()) {
55 result.push(
'.. ...');
57 else if (/[A-Z]/.test(ch)) {
58 const index = letters.indexOf(ch ===
'J' ?
'I' : ch);
59 const row = Math.floor(index / 5) + 1;
60 const col = (index % 5) + 1;
62 result.push(
'.'.repeat(row) +
' ' +
'.'.repeat(col));
70 return result.join(
' / ');
80 decode(ciphertext:
string):
string {
90 const [rowDots, colDots] = token.split(
' ');
93 if (!rowDots || !colDots) {
97 const row = rowDots.length;
98 const col = colDots.length;
99 const index = (row - 1) * 5 + (col - 1);
101 return letters[index] ??
'?';
Abstract base class providing common functionality for cipher implementations.
Implementation of the Tap Code prisoner communication cipher.
static readonly ALPHABET
Modified alphabet for 5×5 grid (excludes J, shares with I)
constructor()
Constructor for Tap Code cipher.
readonly CipherName
Identifier name for this cipher.
export const Record< string,(...args:any[])=> string