-
Notifications
You must be signed in to change notification settings - Fork 13
/
sexy.common.js
99 lines (83 loc) · 2.14 KB
/
sexy.common.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
'use strict';
var level = 0;
var level_load = undefined;
var level_data = undefined;
var last_key = 'hello';
var gen_puzzle = function (code, key) {
var result = CryptoJS.AES.encrypt(code, last_key).toString();
last_key = key;
return result;
};
var gen_salt = function (key) {
return 'salt_' + key + key + key;
};
var load_puzzle = function (key) {
try {
eval(
CryptoJS
.AES
.decrypt(level_data[level], key)
.toString(CryptoJS.enc.Utf8)
);
} catch (e) {
// ignore
}
};
var load_next = function () {
level = level_load + 1;
load_puzzle($('#key').val().toLowerCase());
};
var load_next_salt = function () {
level = level_load + 1;
load_puzzle(gen_salt($('#key').val().toLowerCase()));
};
var load_any = function () {
for (var i in level_data) {
level = parseInt(i);
load_puzzle($('#key').val().toLowerCase());
}
};
var init_puzzle = function (title, content, hint, loader) {
level_load = level;
$('#puzzle').empty();
if (title) {
$('#puzzle').append(
$('<h2 />')
.attr('id', 'title')
.text('Level ' + level + ': ' + title)
);
}
if (content) {
$('#puzzle').append(
$('<div />')
.append(content)
);
} else {
$('#puzzle').append(
$('<div />')
.append(" ")
);
}
$('#puzzle').append(
$('<div />')
.append(
$('<input />')
.attr('id', 'key')
.attr('type', 'text')
.val(hint ? hint : '')
.keypress(function (e) {
if (e.which == 13) {
$('#go').click();
}
})
)
.append(
$('<input />')
.attr('id', 'go')
.attr('type', 'button')
.val('Go!')
.click(loader ? loader : load_next)
)
);
$('#key').select();
};