-
Notifications
You must be signed in to change notification settings - Fork 3
/
short.html
182 lines (169 loc) · 5.22 KB
/
short.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
/>
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>stopsopa.github.io</title>
<style>
label {
display: inline-block;
width: 140px;
text-align: right;
}
.block {
line-height: 2em;
}
.b {
display: inline-block;
width: 23px;
}
.hide .hide {
display: none;
}
body a[disabled] {
color: gray;
}
.wide {
width: 100%;
}
</style>
</head>
<body class="layout hide">
<div class="body">
<div class="inside">
<h2>Links</h2>
<ul>
<li>
<a
data-xor="XQgeDwMBHhpJGlBBFg0YB08MRAlWBg0CXEcJAVRGDhxQHw9BXwYGClwbGUEIADJbUxkQJnQgG1gMOiwICgA6BXgRAF9/PxkUcRo5G19WHx1JVBkGWBsDAF4="
>for HMRC</a
>
</li>
</ul>
<div>
<div class="block hide">
<label> input </label>
<input type="text" class="input" />
</div>
<div class="block">
<label> password </label>
<input type="text" class="pass" />
</div>
<div class="block hide">
<label> decoded: </label>
<a class="decoded"></a>
</div>
<div class="block hide">
<label> encoded: </label>
<input type="text" class="encoded" />
</div>
</div>
</div>
</div>
<a href="https://docs.google.com/document/d/1f6vd4sHT-oms6mcmYTZ7J_zXGmYXquFDTzF4UdFOgRo/edit">p</a>
<button class="b">b</button>
<script src="/js/github.js"></script>
<script>
function xor(data, key) {
if (typeof key !== "string") {
throw new Error(`xor.js: key is not a string`);
}
if (!key) {
throw new Error(`xor.js: key is an empty string`);
}
if (typeof data !== "string") {
throw new Error(`xor.js: data is not a string`);
}
var ret = "",
l = key.length;
for (var i = 0; i < data.length; i++) {
ret += String.fromCharCode(key.charCodeAt(i % l) ^ data.charCodeAt(i));
}
return ret;
}
function toBase(data) {
return btoa(data);
}
function fromBase(data) {
return atob(data);
}
function encode(data, key) {
try {
return toBase(xor(`data:${data}`, key));
} catch (e) {
log("encode error", e);
return "";
}
}
function decode(data, key) {
try {
return xor(fromBase(data), key);
} catch (e) {
log("decode error", e);
return "";
}
}
Array.from(document.querySelectorAll("[data-xor]")).forEach((a) => {
const wide = document.createElement("input");
wide.classList.add("wide");
wide.classList.add("hide");
const u = unique();
wide.setAttribute("id", u);
a.dataset.wide = u;
manipulation.after(a, wide);
const raw = document.createElement("input");
raw.classList.add("wide");
raw.classList.add("hide");
manipulation.after(a, raw);
raw.value = a.getAttribute("data-xor");
});
const input = document.querySelector(".input"); // input
const pass = document.querySelector(".pass"); // input
const decoded = document.querySelector(".decoded"); // a
const encoded = document.querySelector(".encoded"); // input
function trigger() {
const d = decode(input.value, pass.value);
decoded.setAttribute("href", d);
decoded.innerText = d;
encoded.value = encode(input.value, pass.value);
Array.from(document.querySelectorAll("[data-xor]")).forEach((a) => {
const encoded = a.getAttribute("data-xor");
const decoded = decode(encoded, pass.value);
a.classList.remove("valid");
a.setAttribute("href", `javascript:void()`);
a.setAttribute("disabled", "disabled");
const u = document.getElementById(a.dataset.wide) || {};
u.value = decoded;
if (decoded.indexOf("data:") === 0) {
const decodedCut = decoded.substring(5);
a.classList.add("valid");
a.setAttribute("href", decodedCut);
a.removeAttribute("disabled");
window.w = a.dataset.wide;
u.value = decodedCut;
}
});
}
trigger();
input.addEventListener("input", trigger);
pass.addEventListener("input", trigger);
const b = document.querySelector(".b");
b.addEventListener("click", () => {
document.body.classList.toggle("hide");
});
function unique(pattern) {
// node.js require('crypto').randomBytes(16).toString('hex');
pattern || (pattern = "xyxyxy");
return pattern.replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
</script>
</body>
</html>