From eeb9c62cefe26aa372f88f554876037e8d8d3048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D1=83=D0=BA=D0=B0?= <164436043+diamond-ore@users.noreply.github.com> Date: Fri, 26 Apr 2024 21:50:36 -0400 Subject: [PATCH] More encodings --- techdemos/encode/js/main.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/techdemos/encode/js/main.js b/techdemos/encode/js/main.js index f7889e9..32ccb52 100644 --- a/techdemos/encode/js/main.js +++ b/techdemos/encode/js/main.js @@ -9,6 +9,14 @@ const codes = { encode: text => btoa(text), decode: text => atob(text) }, + "Base16 (Hexadecimal)": { + encode: text => text.split("").map(c => c.charCodeAt(0).toString(16).padStart(2, "0")).join("").toUpperCase(), + decode: text => text.split(/(\w\w)/g).filter(p => !!p).map(c => String.fromCharCode(parseInt(c, 16))).join("") + }, + "Base2 (Binary)": { + encode: text => text.split("").map(c => c.charCodeAt(0).toString(2).padStart(8, "0")).join(" "), + decode: text => text.split(" ").filter(p => !!p).map(c => String.fromCharCode(parseInt(c, 2))).join("") + }, "URL": { encode: text => encodeURI(text), decode: text => decodeURI(text) @@ -16,7 +24,11 @@ const codes = { "URL (component)": { encode: text => encodeURIComponent(text), decode: text => decodeURIComponent(text) - } + }, + "URL (aggressive)": { + encode: text => "%" + text.split("").map(c => c.charCodeAt(0).toString(16).padStart(2, "0")).join("%").toUpperCase(), + decode: text => text.split("%").filter(p => !!p).map(c => String.fromCharCode(parseInt(c, 16))).join("") + }, } for (const code in codes) { let element = document.createElement("option");