Skip to content

Instantly share code, notes, and snippets.

@dmjcomdem
Created July 26, 2017 12:36
Show Gist options
  • Save dmjcomdem/1a2fc5c8772c4c93447c0d50acb8b4d6 to your computer and use it in GitHub Desktop.
Save dmjcomdem/1a2fc5c8772c4c93447c0d50acb8b4d6 to your computer and use it in GitHub Desktop.
Простой способ Ceasars Cipher Encryptor (сдвиг позиции буквы в алфавите )
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toLowerCase(),
otherCharacters = '-=~\"\'#$%&*^:<>?/!{(|)}.1234567890\, ';
var shiftedAlphabet = alphabet.slice(3);
shiftedAlphabet += alphabet.slice(0, 3);
shiftedAlphabet += otherCharacters;
alphabet += otherCharacters;
var str = 'I am amazing'.toLowerCase(),
out = '';
for(var i = 0; i < str.length; i++){
var numberd = alphabet.indexOf( str[i] )
out += shiftedAlphabet[numberd];
}
console.log(out) // I am amazing => l dp dpdclqj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment