mirror of
https://github.com/rudimuc/obsidian-coder.git
synced 2026-07-22 09:00:29 +00:00
51 lines
No EOL
1.3 KiB
TypeScript
51 lines
No EOL
1.3 KiB
TypeScript
import {Coder} from "./Coder";
|
|
|
|
export class AtbashEncoder implements Coder {
|
|
from: string;
|
|
to: string;
|
|
|
|
constructor() {
|
|
this.from = "text";
|
|
this.to = "atbash";
|
|
}
|
|
|
|
atbash(txt: string) {
|
|
return txt.replace(/[a-z]/gi, c =>
|
|
"ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba"
|
|
["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".indexOf(c)]);
|
|
}
|
|
|
|
transform(text: string): string {
|
|
return this.atbash(text);
|
|
}
|
|
|
|
checkInput(text: string): boolean {
|
|
// For now, we assume that all text is valid. We will only encode A-Z and a-z. The rest will be left as is.
|
|
return true;
|
|
}
|
|
}
|
|
|
|
export class AtbashDecoder implements Coder {
|
|
from: string;
|
|
to: string;
|
|
|
|
constructor() {
|
|
this.from = "atbash";
|
|
this.to = "text";
|
|
}
|
|
|
|
deatbash(txt: string) {
|
|
return txt.replace(/[a-z]/gi, c =>
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
["ZYXWVUTSRQPONMLKJIHGFEDCBAzyxwvutsrqponmlkjihgfedcba".indexOf(c)]);
|
|
}
|
|
|
|
transform(text: string): string {
|
|
return this.deatbash(text);
|
|
}
|
|
|
|
checkInput(text: string): boolean {
|
|
// For now, we assume that all text is valid. We will only encode A-Z and a-z. The rest will be left as is.
|
|
return true;
|
|
}
|
|
} |