-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_des.js
28 lines (26 loc) · 1.14 KB
/
script_des.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
document.getElementById('left-button').addEventListener('click', function() {
var text = document.getElementById('text1').value;
var key = document.getElementById('text3').value;
if (text === '' || key === '') {
alert('Please enter both text and key.');
return;
}
var encrypted = CryptoJS.DES.encrypt(text, key).toString();
document.getElementById('text2').value = encrypted;
});
document.getElementById('right-button').addEventListener('click', function() {
var encryptedText = document.getElementById('text2').value;
var key = document.getElementById('text3').value;
if (encryptedText === '' || key === '') {
alert('Please enter both encrypted text and key.');
return;
}
var decrypted = CryptoJS.DES.decrypt(encryptedText, key);
var decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
document.getElementById('text1').value = decryptedText;
});
document.getElementById('clear-button').addEventListener('click', function() {
document.getElementById('text1').value = '';
document.getElementById('text2').value = '';
document.getElementById('text3').value = '';
});