Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Atbash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
}
17 changes: 16 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import { App, MarkdownView, Plugin, MarkdownPostProcessorContext, PluginSettingT
import { Coder } from "./Coder";
import { Base64Encoder, Base64Decoder } from "./Base64";
import { Rot13Encoder, Rot13Decoder } from "./Rot13";
import { AtbashEncoder, AtbashDecoder } from "./Atbash";

export default class CoderPlugin extends Plugin {

// List of coders
coders: Coder[] = [new Base64Encoder(), new Base64Decoder(), new Rot13Encoder(), new Rot13Decoder()];
coders: Coder[] = [new Base64Encoder(), new Base64Decoder(), new Rot13Encoder(), new Rot13Decoder(), new AtbashEncoder(), new AtbashDecoder()];

async onload() {
this.registerMarkdownCodeBlockProcessor('transform-text-base64', this.processTextToBase64);
this.registerMarkdownCodeBlockProcessor('transform-base64-text', this.processBase64ToText);
this.registerMarkdownCodeBlockProcessor('transform-text-rot13', this.processTextToRot13);
this.registerMarkdownCodeBlockProcessor('transform-rot13-text', this.processRot13ToText);
this.registerMarkdownCodeBlockProcessor('transform-text-atbash',this.processTextToAtbash);
this.registerMarkdownCodeBlockProcessor('transform-atbash-text',this.processAtbashToText);


}

// function to get a coder by from and to types
Expand Down Expand Up @@ -50,6 +55,16 @@ export default class CoderPlugin extends Plugin {
this.processText(content, el, coder);
}

processTextToAtbash = async (content: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
let coder = this.getCoder("text", "atbash");
this.processText(content, el, coder);
}

processAtbashToText = async (content: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
let coder = this.getCoder("atbash", "text");
this.processText(content, el, coder);
}

processText(content: string, el: HTMLElement, coder: Coder|null) {
var destination;

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Encoder/Decoder",
"version": "1.2.0",
"minAppVersion": "0.15.0",
"description": "Converts texts into other formats (base64, ROT13) and vice versa",
"description": "Converts texts into other formats (base64, ROT13, atbash) and vice versa",
"author": "Rudi Häusler",
"isDesktopOnly": false
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "coder",
"version": "1.1.0",
"description": "Converts text into other formats (base64, ROT13)",
"description": "Converts text into other formats (base64, ROT13, atbash)",
"main": "main.js",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down