-
Notifications
You must be signed in to change notification settings - Fork 12
/
email.html
103 lines (96 loc) · 3.56 KB
/
email.html
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
<script>
//stolen from here: https://gist.github.com/lyquix-owner/2ad6459672c1b8ec826b0b59f4e220d3
function encrypt(key, plaintext) {
let cyphertext = [];
// Convert to hex to properly handle UTF8
plaintext = Array.from(plaintext).map(function(c) {
if(c.charCodeAt(0) < 128) return c.charCodeAt(0).toString(16).padStart(2, '0');
else return encodeURIComponent(c).replace(/\%/g,'').toLowerCase();
}).join('');
// Convert each hex to decimal
plaintext = plaintext.match(/.{1,2}/g).map(x => parseInt(x, 16));
// Perform xor operation
for (let i = 0; i < plaintext.length; i++) {
cyphertext.push(plaintext[i] ^ key.charCodeAt(Math.floor(i % key.length)));
}
// Convert to hex
cyphertext = cyphertext.map(function(x) {
return x.toString(16).padStart(2, '0');
});
return cyphertext.join('');
}
// Super simple XOR decrypt function
function decrypt(key, cyphertext) {
try {
cyphertext = cyphertext.match(/.{1,2}/g).map(x => parseInt(x, 16));
let plaintext = [];
for (let i = 0; i < cyphertext.length; i++) {
plaintext.push((cyphertext[i] ^ key.charCodeAt(Math.floor(i % key.length))).toString(16).padStart(2, '0'));
}
return decodeURIComponent('%' + plaintext.join('').match(/.{1,2}/g).join('%'));
}
catch(e) {
return false;
}
}
// Super simple password to 256-bit key function
function passwordDerivedKey(password, salt, iterations, len) {
if(!password) password = randomStr();
if(!salt) salt = '80ymb4oZ';
if(!iterations) iterations = 8;
if(!len) len = 256;
len = Math.ceil(len / 8);
var key = '';
while(key.length < len) {
var i = 0;
var intSalt = salt;
var intKey = '';
while(i < iterations) {
intKey = hash(password + intSalt);
var newSalt = '';
for(let j = 0; j < intSalt.length; j++) {
newSalt += (intSalt.charCodeAt(j) ^ intKey.charCodeAt(Math.floor(j % intKey.length))).toString(36);
}
intSalt = newSalt;
i++;
}
key += intKey;
}
return key.substring(0, len);
}
// Generates a random string of the specificed length
function randomStr(len) {
var str = parseInt(Math.random()*10e16).toString(36);
if(typeof len == 'undefined') return str;
else {
while(str.length < len) {
str += parseInt(Math.random()*10e16).toString(36);
}
return str.substring(str.length - len);
}
}
// Super simple hash function
function hash(str) {
for(var i = 0, h = 4641154056; i < str.length; i++) h = Math.imul(h + str.charCodeAt(i) | 0, 2654435761);
h = (h ^ h >>> 17) >>> 0;
return h.toString(36);
}
function handler() {
var asd = document.getElementById("asd").value;
var key = passwordDerivedKey(asd);
var enc = "5c56050b781b54530a014a00455d0917160359";
var decrypted = decrypt(key, enc);
console.log(decrypted);
if (decrypted.codePointAt(4) == "@".codePointAt(0)) {
document.getElementById("question").innerHTML = '<a href="mailto:' + decrypted + '">' + decrypted + "</a>";
}
else {
alert("Niepoprawna odpowiedź. Napisz małymi literami.");
}
}
</script>
<body>
<p id="prompt">Zabezpieczenie przeciwspamowe. Aby zobaczyć e-mail, odpowiedz na pytanie: </p>
<h1 id="question">Zwierzę, które szczeka to (4 litery): </h1>
<input id="asd" maxlength="4">
<input type="submit" onclick="handler()" value="Odszyfruj">