Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Caesar Cipher (encryptor) by mortonfox
"use strict";
function toEncrypt(text, delta) {
return text.split('').map(c => c === ' ' ? ' ' : String.fromCharCode((c.charCodeAt(0) - 'a'.charCodeAt(0) + delta + 26) % 26 + 'a'.charCodeAt(0))).join('');
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(toEncrypt('abc', 10))
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(toEncrypt("a b c", 3), "d e f")
assert.equal(toEncrypt("a b c", -3), "x y z")
assert.equal(toEncrypt("simple text", 16), "iycfbu junj")
assert.equal(toEncrypt("important text", 10), "swzybdkxd dohd")
assert.equal(toEncrypt("state secret", -13), "fgngr frperg")
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Aug. 2, 2018