Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Caesar Cipher (encryptor) by SaintDron
"use strict";
function toEncrypt(text, delta) {
const chars = "abcdefghijklmnopqrstuvwxyz".repeat(3);
let result = '';
for (let c of text) {
result += (c === ' ') ? ' ' : chars[chars.indexOf(c, 26) + delta];
}
return result;
}
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. 26, 2018