forked from mdforhadsarker/OnlineEncryptAndDecrypt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainscript.js
127 lines (75 loc) · 2.71 KB
/
mainscript.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var a='Please enter encryption type';
//encryption function
function enc(){
var tp = document.getElementById('method').value;
var kk = document.getElementById("key").value;
var pp = document.getElementById("plain").value;
switch(tp){
case 'def':
document.getElementById("chipher").innerText = a;
break;
case 'aes':
var encrypted = CryptoJS.AES.encrypt(pp, kk);
document.getElementById("chipher").innerText = encrypted;
break;
case 'des':
var encrypted = CryptoJS.TripleDES.encrypt(pp, kk);
document.getElementById("chipher").innerText = encrypted;
break;
case 'rc4':
var encrypted = CryptoJS.RC4.encrypt(pp, kk);
document.getElementById("chipher").innerText = encrypted;
break;
case 'rb':
var encrypted = CryptoJS.Rabbit.encrypt(pp, kk);
document.getElementById("chipher").innerText = encrypted;
break;
default:
break;
}
}
//decryption function
function dec(){
var tp = document.getElementById('method').value;
var kk = document.getElementById("key").value;
var pp = document.getElementById("plain").value;
switch(tp){
case 'def':
document.getElementById("chipher").innerText = a;
break;
case 'des':
var decrypted = CryptoJS.TripleDES.decrypt(pp, kk);
document.getElementById("chipher").innerText = (decrypted.toString(CryptoJS.enc.Utf8));
break;
case 'aes':
var decrypted = CryptoJS.AES.decrypt(pp, kk);
document.getElementById("chipher").innerText = (decrypted.toString(CryptoJS.enc.Utf8));
break;
case 'rc4':
var decrypted = CryptoJS.RC4.decrypt(pp, kk);
document.getElementById("chipher").innerText = (decrypted.toString(CryptoJS.enc.Utf8));
break;
case 'rb':
var decrypted = CryptoJS.Rabbit.decrypt(pp, kk);
document.getElementById("chipher").innerText = (decrypted.toString(CryptoJS.enc.Utf8));
break;
default:
break;
}
}
// HASH functions
function sha1(){
var pp = document.getElementById("plain").value;
var hash1 = CryptoJS.SHA1(pp);
document.getElementById("chipher").innerText = hash1.toString(CryptoJS.enc.Base64);
}
function md(){
var pp = document.getElementById("plain").value;
var hash = CryptoJS.MD5(pp);
document.getElementById("chipher").innerText = hash.toString(CryptoJS.enc.Base64);
}
function sha3(){
var pp = document.getElementById("plain").value;
var hash2 = CryptoJS.SHA3(pp,{ outputLength: 224 })
document.getElementById("chipher").innerText = hash2.toString(CryptoJS.enc.Base64);
}