-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
69 lines (66 loc) · 2.75 KB
/
index.html
File metadata and controls
69 lines (66 loc) · 2.75 KB
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
<!DOCTYPE html>
<html>
<head>
<title>异或操作编码解码</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
function strlen(str) {
return str.length;
}
function decrypt(str, key) {
const len = strlen(str);
let decrypt = '';
for (let i = 0; i < len; i++) {
const encryptedChar = str.charCodeAt(i) ^ key.charCodeAt(i % strlen(key));
decrypt += String.fromCharCode(encryptedChar);
}
return decrypt;
}
function encrypt(str, key) {
const len = strlen(str);
let first_encrypt = '';
let first_encrypt_2 = '';
let second_encrypt = '';
for (let i = 0; i < len; i++) {
let encryptedChar = str.charCodeAt(i) ^ key.charCodeAt(i % strlen(key));
let encryptedChar2 = encryptedChar;
if (encryptedChar2 < 32 || encryptedChar2 > 126) {
encryptedChar2 = 63;
}
first_encrypt += String.fromCharCode(encryptedChar);
first_encrypt_2 += String.fromCharCode(encryptedChar2);
}
second_encrypt = decrypt(first_encrypt, key);
return [first_encrypt_2, second_encrypt];
}
function encryptAndDecrypt() {
const plaintext = document.getElementById("plaintext").value;
const key = document.getElementById("key").value;
const result = encrypt(plaintext, key);
document.getElementById("first_encrypt").innerHTML = result[0];
document.getElementById("second_encrypt").innerHTML = result[1];
}
</script>
</head>
<body>
<h1>异或XOR编码解码(题.8 信息加密)</h1>
<p><span style="font-size: 18px; color: rgb(230, 46, 46);">C语言高级程序语言设计 by hyz lyk bz</span></p>
<p><span style="font-size: 20px; color: rgb(33, 29, 243);">
请输入明文和密钥
</span></p>
<label for="plaintext">明文(不超过200字符):</label>
<textarea id="plaintext" rows="4" cols="50" style="width: 425px; height: 127px;"></textarea><br><br>
<label for="key">密钥Key(不超过20字符):</label>
<input type="text" id="key" name="key"><br><br>
<button onclick="encryptAndDecrypt()"
style="font-size: 29px; color: red;">开始异或</button>
<br><br>
<p style="font-weight: bold;">结果</p><br>
<label for="first_encrypt">第一次异或:</label>
<p id="first_encrypt"></p>
<br>
<label for="second_encrypt">第二次异或:</label>
<p id="second_encrypt"></p>
</body>
</html>