Spaces:
Running
Running
Create script.js
Browse files
script.js
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
function caesarCipher(str, shift) {
|
2 |
+
return str.split('').map(char => {
|
3 |
+
if (char.match(/[a-z]/i)) {
|
4 |
+
let code = char.charCodeAt();
|
5 |
+
|
6 |
+
if ((code >= 65) && (code <= 90))
|
7 |
+
return String.fromCharCode(((code - 65 + shift) % 26) + 65);
|
8 |
+
|
9 |
+
else if ((code >= 97) && (code <= 122))
|
10 |
+
return String.fromCharCode(((code - 97 + shift) % 26) + 97);
|
11 |
+
}
|
12 |
+
return char;
|
13 |
+
}).join('');
|
14 |
+
}
|
15 |
+
|
16 |
+
function vigenereCipher(text, key) {
|
17 |
+
let output = '';
|
18 |
+
key = key.toUpperCase();
|
19 |
+
|
20 |
+
for (let i = 0, j = 0; i < text.length; i++) {
|
21 |
+
let c = text.charAt(i);
|
22 |
+
|
23 |
+
if (c.match(/[a-z]/i)) {
|
24 |
+
let code = text.charCodeAt(i);
|
25 |
+
if ((code >= 65) && (code <= 90))
|
26 |
+
c = String.fromCharCode(((code - 65 + key.charCodeAt(j % key.length) - 65) % 26) + 65);
|
27 |
+
else if ((code >= 97) && (code <= 122))
|
28 |
+
c = String.fromCharCode(((code - 97 + key.charCodeAt(j % key.length) - 65) % 26) + 97);
|
29 |
+
|
30 |
+
j++;
|
31 |
+
}
|
32 |
+
output += c;
|
33 |
+
}
|
34 |
+
return output;
|
35 |
+
}
|
36 |
+
|
37 |
+
function encryptText() {
|
38 |
+
const inputText = document.getElementById('inputText').value;
|
39 |
+
const method = document.getElementById('encryptionMethod').value;
|
40 |
+
let encryptedText = '';
|
41 |
+
|
42 |
+
if (method === 'caesar') {
|
43 |
+
const shift = 3; // You can customize the shift value
|
44 |
+
encryptedText = caesarCipher(inputText, shift);
|
45 |
+
} else if (method === 'vigenere') {
|
46 |
+
const key = 'KEY'; // You can customize the key
|
47 |
+
encryptedText = vigenereCipher(inputText, key);
|
48 |
+
} else if (method === 'aes') {
|
49 |
+
// AES encryption will require more complex setup, usually handled server-side
|
50 |
+
encryptedText = 'AES Encryption is more complex and is usually done on the server-side.';
|
51 |
+
}
|
52 |
+
|
53 |
+
document.getElementById('outputText').value = encryptedText;
|
54 |
+
}
|