Last active
January 21, 2022 05:23
-
-
Save hareom284/e864fdff369ce00f80195d9a5372d27c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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