forked from surajondev/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
22 lines (19 loc) · 797 Bytes
/
script.js
File metadata and controls
22 lines (19 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function Encrypt() {
let plainText = document.getElementById("plain-text").value;
let key = parseInt(document.getElementById("key").value);
let cipheredText = "";
for( var position = 0; position < plainText.length; position++) {
var letter = plainText[position];
if(letter.match(/[a-z]/i)){
var code = parseInt(plainText.charCodeAt(position));
if (code >= 65 && code <= 90) {
letter = String.fromCharCode(((code - 65 + key) % 26) + 65);
}
else if (code >= 97 && code <= 122) {
letter = String.fromCharCode(((code - 97 + key) % 26) + 97);
}
}
cipheredText += letter;
}
document.getElementById("encrypted-text").innerHTML = cipheredText;
}