Skip to content

Instantly share code, notes, and snippets.

@jamierocks jamierocks/cipher.js
Last active Aug 29, 2015

Embed
What would you like to do?
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function cipher(input, shift) {
var result = '';
for (var i = 0; i < input.length; i++) {
var position = alphabet.indexOf(input[i].toUpperCase()) + Math.floor(shift);
if (position > 25) {
position -= 26;
}
result = result.concat(alphabet[position]);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.