-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
203 lines (186 loc) · 7.47 KB
/
index.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta name="author" content="[email protected]">
<meta name="author" content="https://zeeg.me/gregtonoski">
<meta http-equiv="creation-date" content="2024-07-31T13:00Z">
<meta name="description" content="Convert from SylUI to hex code.">
<title>Sylui demo example</title>
<style>
body {
font: 1em sans-serif;
width: 600px;
padding: 0;
margin: 0 auto;
}
div {
height: 200px;
}
form {
max-width: 600px;
}
p * {
display: block;
}
input#userInputText1 {
appearance: none;
width: 100%;
border: 1px solid #333;
margin: 0;
font-family: monospace, monospace;
font-size: 90%;
box-sizing: border-box;
}
input.invalid {
border-color: #900;
background-color: #fdd;
}
input:focus:invalid {
outline: none;
}
.error {
width: 100%;
padding: 0;
font-size: 80%;
color: white;
background-color: #900;
border-radius: 0 0 5px 5px;
box-sizing: border-box;
}
.error.active {
padding: 0.3em;
}
output {
font-family: monospace, monospace;
font-size: 90%;
}
.mono {
font-family: monospace, monospace;
font-size: 90%;
}
</style>
</head>
<body>
<div>
<form>
<p>
<label for="userInputText1">
<span>Enter SylUI code:</span>
<input type="text" id="userInputText1" name="userInputText1" size="10" autocomplete="off" autofocus />
<span class="error" aria-live="polite"></span>
</label>
<span id="textInputCharacters"></span>
</p>
<button id="btnSubmit">Convert to hex code</button>
</form>
<p id="outputParagraph">
</p>
<script>
const form = document.querySelector("form");
let inputSylUI = document.getElementById("userInputText1");
const error = inputSylUI.nextElementSibling;
const inputSylUIRegExp = /^[bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ]?\s*(?:[aeyouiAEYOUI]\s*[bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ]?\s*)*$/;
const submitRegExp = /^(?:[bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ]?\s*[aeyouiAEYOUI]\s*)*$/;
window.addEventListener("load", () => {
const isValid = inputSylUI.value.length === 0 || inputSylUIRegExp.test(inputSylUI.value);
inputSylUI.className = isValid ? "valid" : "invalid";
});
inputSylUI.addEventListener("input", () => {
document.getElementById("outputParagraph").innerHTML = '';
if (inputSylUI.value) {
document.getElementById("textInputCharacters").innerHTML = inputSylUI.value.match(/\S/g).length + ' characters in total.';
} else {
document.getElementById("textInputCharacters").innerHTML = '';
}
const isValid = inputSylUI.value.length === 0 || inputSylUIRegExp.test(inputSylUI.value);
if (isValid) {
inputSylUI.className = "valid";
error.textContent = "";
error.className = "error";
} else {
inputSylUI.className = "invalid";
}
});
form.addEventListener("submit", (event) => {
event.preventDefault();
const isValid = inputSylUI.value.length === 0 || submitRegExp.test(inputSylUI.value);
if (!isValid) {
inputSylUI.className = "invalid";
error.textContent = "Incorrect SylUI code entered.";
error.className = "error active";
} else {
inputSylUI.className = "valid";
error.textContent = "";
error.className = "error";
if (inputSylUI.value.length === 0) {
document.getElementById("userInputText1").value = randomSylUI();
inputSylUI = document.getElementById("userInputText1");
}
document.getElementById("textInputCharacters").innerHTML = inputSylUI.value.match(/\S/g).length + ' characters in total.';
const numberHex = sylUI2Hex(inputSylUI.value);
document.getElementById("outputParagraph").innerHTML = 'Hex code (' + numberHex.match(/\S/g).length + ' characters):<br><output>' + numberHex + '</output>';
}
});
const syllables = ["a", "e", "i", "o", "u", "y", "ba", "be", "bi", "bo", "bu", "by", "ca", "ce", "ci", "co", "cu", "cy", "da", "de", "di", "do", "du", "dy", "fa", "fe", "fi", "fo", "fu", "fy", "ga", "ge", "gi", "go", "gu", "gy", "ha", "he", "hi", "ho", "hu", "hy", "ja", "je", "ji", "jo", "ju", "jy", "ka", "ke", "ki", "ko", "ku", "ky", "la", "le", "li", "lo", "lu", "ly", "ma", "me", "mi", "mo", "mu", "my", "na", "ne", "ni", "no", "nu", "ny", "pa", "pe", "pi", "po", "pu", "py", "qa", "qe", "qi", "qo", "qu", "qy", "ra", "re", "ri", "ro", "ru", "ry", "sa", "se", "si", "so", "su", "sy", "ta", "te", "ti", "to", "tu", "ty", "va", "ve", "vi", "vo", "vu", "vy", "wa", "we", "wi", "wo", "wu", "wy", "xa", "xe", "xi", "xo", "xu", "xy", "za", "ze", "zi", "zo", "zu", "zy"];
function sylUI2Hex(sylText) {
let number = BigInt(0);
let exponent= BigInt(0);
let addend = BigInt(0);
let radix = BigInt(126);
const re = /[bcdfghjklmnpqrstvwxz]?\s*[aeyoui]/gi ;
sylText = sylText.replaceAll(/\s/g , "");
const digits = sylText.match(re);
exponent = BigInt(digits.length - 1);
for (const digit of digits) {
addend = BigInt(syllables.indexOf(digit.toLowerCase()));
addend = addend*radix**exponent;
number = number + addend;
exponent--;
addend = 0;
}
return number.toString(16);
}
function randomSylUI() {
let str = '';
// 36 syllables encode numbers of size up to 252 bits. 37 syllables encode slighly more than 256 bits.
for (let i = 1; i <= 36; i++) {
str = str + syllables[Math.floor(Math.random()*syllables.length)];
if (! (i % 3)) {
str = str + ' ';
}
}
return str;
}
</script>
</div>
<div>
<p>SylUI is encoding that makes it more user-friendly to manually copy secrets or random numbers.
</p>
<p>
Example:
</p>
<p>
<span class="mono">duboli kufuzu naleqy lyfety dohihy rutoqa rageli kilyly vetyka himujy teluzi fuoda va</span>
</p>
<p>
which corresponds to both:
<ul>
<li><span class="mono">nsec1epd0htx08c0wgz7u6us6ntgngy6ywaw4rpqwlsz3rcqc9t5j778q75xnrg</span></li>
<li><span class="mono">c85afbaccf3e1ee40bdcd721a9ad1341344775d51840efc0511e0182ae92f78e</span></li>
</ul>
</p>
<p>More information:
<ul>
<li>
<a href="https://docs.google.com/presentation/d/e/2PACX-1vRVNGfx9-cq6i1iKlSp0u0kYZPHZJSPxsfpFtgScQA3QG6lJCqOE7kFHd5stL1-wnyDlqhRJU0TFbv8/pub?start=false&loop=false&delayms=3000">SylUI introduction</a>
</li>
<li>
<a href="https://github.com/GregTonoski/sylui">https://github.com/GregTonoski/sylui</a>
</li>
</ul>
</p>
</div>
</body>
</html>