Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
rosetta my old friend solution in Clear category for [old] Caesar Cipher (encryptor) by vincent.tscherter
"use strict";
function toEncrypt(text, delta) {
// http://www.rosettacode.org/wiki/Caesar_cipher#JavaScript
return text.replace(/[a-z]/g, a =>
String.fromCharCode(97 + (a.charCodeAt(0) - 71 + delta) % 26));
}
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!");
}
May 24, 2018
Comments: