Skip to content

Instantly share code, notes, and snippets.

@hareom284
Last active January 21, 2022 05:23
Show Gist options
  • Save hareom284/e864fdff369ce00f80195d9a5372d27c to your computer and use it in GitHub Desktop.
Save hareom284/e864fdff369ce00f80195d9a5372d27c to your computer and use it in GitHub Desktop.
var plaintext = (window.prompt("plaintext:"));
var key = Number(window.prompt("key:"));
var result="";
for(let p of plaintext)
{
if ( p >= 'a' && p <= 'z')
{
p = p.charCodeAt();
p = p - 97;
p = (p + key) % 26;
p = p + 97;
let change = String.fromCharCode(p)
result += change;
}
else if (p >= 'A'&& p<='Z')
{
p =p.charCodeAt()
p = p - 65;
p = (p + key) % 26;
p = p + 65;
let change = String.fromCharCode(p);
result += change;
}
}
console.log("ciphertext :",result )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment