-
Notifications
You must be signed in to change notification settings - Fork 0
/
o7s.html
70 lines (64 loc) · 2.43 KB
/
o7s.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
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>O7S谜语人</title>
</head>
<body>
<textarea id="rawText" class="text_source" style="width:100%;max-width:600px;height:200px" placeholder="在这里输入要加密的文字"></textarea>
<p>
<button id="encodeButton" onclick="input2.value = o7sencode(input1.value)">加密</button>
<button id="decodeButton" onclick="input1.value = o7sdecode(input2.value)">解密</button>
<button id="clearButton" onclick="input1.value = '';input2.value = ''">清空</button>
</p>
<textarea id="O7SCode" class="text_source" style="width:100%;max-width:600px;height:200px" placeholder="在这里输入要解密的文字"></textarea>
<script>
var input1 = document.getElementById('rawText'),
input2 = document.getElementById('O7SCode')
const o7sDictArr = ["达达", "飞机", "墨鱼", "图书"]
function o7sencode(rawStr) {
let charArr = rawStr.split("")
let unicodeHexStr = ""
for (let i = 0; i < charArr.length; i++) {
let charHexStr = charArr[i].charCodeAt(0).toString(16)
while (charHexStr.length < 4) charHexStr = "0" + charHexStr
unicodeHexStr += charHexStr
}
let k = 0
let unicodeHexStrArr = unicodeHexStr.split("")
let o7sStr = ""
for (let i = 0; i < unicodeHexStrArr.length; i++) {
let unicodeHexCharValue = parseInt("0x" + unicodeHexStrArr[i])
k = unicodeHexCharValue + (i % 0x10)
if (k >= 0x10) k = k - 0x10
o7sStr += o7sDictArr[parseInt(k / 4)] + o7sDictArr[(k % 4)]
}
return o7sStr
}
function o7sdecode(o7sStr) {
let unicodeHexStr = ""
let o7sStrArr = o7sStr.split("")
for (let i = 0; i <= (o7sStr.length - 4); i += 4) {
for (j = 0; j <= 3; j++) if (o7sStrArr[i] == o7sDictArr[j][0]) break
let k = j*4
for (j=0; j <= 3; j++) if ( o7sStrArr[i + 2] == o7sDictArr[j][0]) break
k += j
let unicodeHexCharValue = k - (parseInt(i / 4) % 0x10)
if (unicodeHexCharValue < 0) unicodeHexCharValue += 0x10
unicodeHexStr += unicodeHexCharValue.toString(16)
}
let rawStr = ""
let start = 0
let end = 4
while (end <= unicodeHexStr.length) {
let charHexStr = unicodeHexStr.substring(start, end)
let charStr = String.fromCharCode(parseInt("0x" + charHexStr))
rawStr += charStr
start += 4
end += 4
}
return rawStr
}
</script>
</body>
</html>