Published
Edited
Sep 28, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function shiftEncrypt(plaintext, key) {
let secret = encode(plaintext);
secret.forEach(function (item, index, arr) {
arr[index] = (item + key) % 26;
});
return decode(secret);
}
Insert cell
function shiftDecrypt(cyphertext, key) {
let message = encode(cyphertext);
message.forEach(function (item, index, arr) {
arr[index] = item - key;
if (arr[index] < 0) {
arr[index] = arr[index] + 26;
}
});
return decode(message);
}
Insert cell
function decode(encoded) {
let decoded = ``;
encoded.forEach(function (item, index, arr) {
decoded += String.fromCharCode(item + 65);
});
return decoded;
}
Insert cell
function encode(string) {
string = string.toUpperCase();
let a = string.split(``);
a = a.filter(function (char) {
if (char.charCodeAt(0) < 65) {
return false;
} else if (char.charCodeAt(0) > 90) {
return false;
} else {
return true;
}
});
a.forEach(function (item, index, arr) {
arr[index] = item.charCodeAt(0) - 65;
});
return a;
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more