-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
110 lines (99 loc) · 3.59 KB
/
index.html
File metadata and controls
110 lines (99 loc) · 3.59 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Uni7cod8</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.container {
max-width: 600px;
margin: 0 auto;
}
textarea {
width: 100%;
height: 100px;
margin-bottom: 10px;
}
button {
margin-right: 10px;
}
.result {
margin-top: 20px;
padding: 10px;
background-color: #f9f9f9;
border: 1px solid #ddd;
}
.language-select {
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="language-select">
<label for="language">语言 / Language:</label>
<select id="language" onchange="changeLanguage()">
<option value="zh">中文</option>
<option value="en">English</option>
</select>
</div>
<h1 id="title">Un7cod8</h1>
<textarea id="inputText" placeholder="Enter your text here... / 在这里输入文本..."></textarea>
<button onclick="encrypt()" id="encryptButton">Encode</button>
<button onclick="decrypt()" id="decryptButton">Decode</button>
<div class="result" id="result"></div>
</div>
<script>
let language = 'zh';
function changeLanguage() {
language = document.getElementById('language').value;
updateText();
}
function updateText() {
const title = document.getElementById('title');
const encryptButton = document.getElementById('encryptButton');
const decryptButton = document.getElementById('decryptButton');
const placeholder = document.getElementById('inputText');
if (language === 'en') {
title.innerText = 'Un7cod8';
encryptButton.innerText = 'Encode';
decryptButton.innerText = 'Decode';
placeholder.placeholder = 'Enter your text here...';
} else if (language === 'zh') {
title.innerText = 'Un7cod8';
encryptButton.innerText = '编码';
decryptButton.innerText = '解码';
placeholder.placeholder = '在这里输入文本...';
}
}
function encrypt() {
const input = document.getElementById('inputText').value;
let result = '';
for (let i = 0; i < input.length; i++) {
const charCode = input.charCodeAt(i);
const binary = charCode.toString(2);
const encrypted = binary.replace(/0/g, '7').replace(/1/g, '8');
result += encrypted + ' ';
}
document.getElementById('result').innerText = result.trim();
}
function decrypt() {
const input = document.getElementById('inputText').value;
let result = '';
const binaryStrings = input.split(' ');
for (let i = 0; i < binaryStrings.length; i++) {
if (binaryStrings[i] === '') continue;
const decrypted = binaryStrings[i].replace(/7/g, '0').replace(/8/g, '1');
const charCode = parseInt(decrypted, 2);
result += String.fromCharCode(charCode);
}
document.getElementById('result').innerText = result;
}
updateText();
</script>
</body>
</html>