Simple Stupid Encryption

Run Settings
LanguageJavaScript
Language Version
Run Command
const {enc, dec} = require("./enc.js"); btoa = x => Buffer.from(x).toString('base64'); atob = x => Buffer.from(x, 'base64').toString(); function encrypt(text) { return btoa([...new Array(text.length)].map((_,i) => (enc(text[i].charCodeAt(0)))).join(":")) } function decrypt(e) { return atob(e).split(":").map(x => String.fromCharCode(dec(+x))).join("") } const original = "https://stackoverflow.com/questions/12332002/how-to-store-a-byte-array-in-javascript️" const encrypted = encrypt(original) console.log(encrypted); const decrypted = decrypt(encrypted); console.log(decrypted) console.log(decrypted === original)
// just a random number const rnd = (p) => Math.floor(Math.random() * (p - 1)) + 1 // our secret, there are maximum `p*p` equivalent ways of representing any number by this obfuscation method const p = 7 const start = 1 // obfuscate i const enc = i => { const r = rnd(p) return r * (i + start) * p + r } // deobfuscate e const dec = e => { const r = e % p const ri = (e - r) / p return (ri / r) - start } module.exports = {enc, dec}
Editor Settings
Theme
Key bindings
Full width
Lines