/
main.js
70 lines (64 loc) · 1.98 KB
/
main.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
$("#crypt-form").on("submit", function (event) {
event.preventDefault();
var key = $('#encrypt-key').val();
if (key == '') { key = 1; }
var crypt = Encrypt($('#text-to-encrypt').val(), key);
$('.encrypted-text').text(crypt);
});
$("#decrypt-form").on("submit", function (event) {
event.preventDefault();
var key = $('#decrypt-key').val();
if (key == '') { key = 1; }
var decrypt = Decrypt($('#text-to-decrypt').val(),key);
$('.decrypted-text').text(decrypt);
});
$('.copy-button-encrypted').on("click", function () {
var copyText = document.getElementById("encrypted-text");
if (copyText.value != '') {
copyText.select();
copyText.setSelectionRange(0, 99999);
navigator.clipboard.writeText(copyText.value);
$('#encrypted-copyed-success').fadeIn().delay(2000).fadeOut('fast');
}
});
$('.copy-button-decrypted').on("click", function () {
var copyText = document.getElementById("decrypted-text");
if (copyText.value != '') {
copyText.select();
copyText.setSelectionRange(0, 99999);
navigator.clipboard.writeText(copyText.value);
$('#decrypted-copyed-success').fadeIn().delay(2000).fadeOut('fast');
}
});
function Encrypt(str, key) {
if (!str) str = "";
str = (str == "undefined" || str == "null") ? "" : str;
try {
var key = key;
var pos = 0;
var ostr = '';
while (pos < str.length) {
ostr = ostr + String.fromCharCode(str.charCodeAt(pos) ^ key);
pos += 1;
}
return ostr;
} catch (ex) {
return '';
}
}
function Decrypt(str, key) {
if (!str) str = "";
str = (str == "undefined" || str == "null") ? "" : str;
try {
var key = key;
var pos = 0;
var ostr = '';
while (pos < str.length) {
ostr = ostr + String.fromCharCode(key ^ str.charCodeAt(pos));
pos += 1;
}
return ostr;
} catch (ex) {
return '';
}
}