generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAtbash.ts
51 lines (41 loc) · 1.31 KB
/
Atbash.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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;
}
}