-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
94 lines (90 loc) · 2.47 KB
/
Copy pathindex.js
File metadata and controls
94 lines (90 loc) · 2.47 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
function stringToCodePoints(str) {
return [...str].map((c) => c.codePointAt(0));
}
function codePointsToString(codePoints) {
return String.fromCodePoint(...codePoints);
}
function calculateKey(code,i) {
return Math.floor(i*Array.from(code).length*(i-1))%10000;
}
function encode(code) {
const codePoints = stringToCodePoints(code);
codePoints_encoded = [...codePoints];
for(let i = 0; i < codePoints.length; i++)
{
if(i>0)
{
const key = calculateKey(code,codePoints_encoded[i-1]**2);
codePoints_encoded[i]=codePoints[i]+key;
}
else
{
const key = 1;
codePoints_encoded[i]=codePoints[i]+key;
}
}
return codePoints_encoded;
}
function decode(code) {
const codePoints = stringToCodePoints(code);
codePoints_decoded = [...codePoints];
for(let i = 0; i <codePoints.length; i++)
{
if(i>0)
{
const key = calculateKey(code,codePoints[i-1]**2);
codePoints_decoded[i]=codePoints[i]-key;
}
else
{
const key = 1;
codePoints_decoded[i]=codePoints[i]-key;
}
}
return codePoints_decoded;
}
function handleOperation(operation) {
const input = document.getElementById("input").value;
try {
let result;
if (operation === "encode") {
const encoded = encode(input);
result = codePointsToString(encoded);
} else {
const decoded = decode(input);
result = codePointsToString(decoded);
}
document.getElementById("output").value = result;
} catch (e) {
alert("Failed!");
}
}
function EnableTypeIn() {
document.getElementById("Name").readOnly =
!document.getElementById("Name").readOnly;
}
function SYC() {
fetch("SYC.html")
.then((r) => r.text())
.then((t) => (document.body.innerHTML = t));
}
function MyPage() {
location.assign("https://github.com/StreamingMoon");
}
function Doing() {
location.assign("https://github.com/StreamingMoon/streamingmoon.github.io");
}
function Detail() {
if (document.getElementById("Name").value === "SYC") {
SYC();
} else {
fetch("detail.html")
.then((r) => r.text())
.then((t) => (document.body.innerHTML = t));
}
}
function Back() {
fetch("index.html")
.then((r) => r.text())
.then((t) => (document.body.innerHTML = t));
}