-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
368 lines (312 loc) · 16.7 KB
/
index.html
File metadata and controls
368 lines (312 loc) · 16.7 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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Encrypt/Decrypt Cycle </title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
}
.note {
background-color: #fff3cd;
border-left: 6px solid #ffeeba;
padding: 10px;
margin: 10px 0;
}
textarea,
input,
select {
width: 100%;
padding: 10px;
border: 0.05rem solid #3263b3;
border-radius: 5px;
font-size: 16px;
margin-bottom: 20px;
}
button {
margin: 5px;
padding: 10px;
background-color: transparent;
border: 1px solid #ccc;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s, transform 0.2s;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
min-width: 400px;
max-width: 800px;
margin-top: 20px;
margin-bottom: 20px;
}
.sub-sub-container {
margin-bottom: 20px;
}
</style>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-KZQQX49T');</script>
<!-- End Google Tag Manager -->
</head>
<body>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KZQQX49T"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<div class="container">
<h1>Encrypt/Decrypt Cycle</h1>
<div class="sub-container">
<label for="inputText">Enter text to process:</label>
<textarea id="inputText" rows="4">The Tughra library provides a framework for encrypting and decrypting text and files of various types using multiple algorithms, including Tughra, Caesar, Vigenère, and XOR. This guide will walk you through how to use the class and its various features.</textarea>
<input type="file" id="file" />
</div>
<div class="sub-container">
<label for="cycles">Number of cycles:</label>
<input type="number" id="cycles" value="3" min="1" />
</div>
<div class="sub-container">
<label for="unicodeGroupInput">Select an Unicode Group:</label>
<select id="unicodeGroupInput" multiple>
</select>
<label for="encryptionKey">Provided key for encryption/decryption operation</label>
<input type="text" id="encryptionKey" value="mEQlLJ5IkPJY7UbW" />
<label for="cycles">Key Length:</label>
<input type="number" id="keylength" value="16" min="1" />
<button onclick="generateKey()">Generate</button>
</div>
<div class="sub-container">
<label for="algorithm">algorithm?</label>
<select id="algorithm">
<option value="default">Tughra</option>
<option value="caesar">CAESAR</option>
<option value="xor">XOR</option>
<option value="vigenere">Vigenere</option>
<option value="ROT47">ROT47</option>
<option value="Atbash">Atbash</option>
<option value="Substitution">Substitution</option>
<option value="Base64">Base64</option>
<option value="ASCII">ASCII Shift</option>
<option value="Affine">Affine</option>
<option value="Unicode Shift">Unicode Shift</option>
<option value="Numeric">Numeric</option>
<option value="Reversed Caesar">Reversed Caesar</option>
<option value="ROT13">ROT13</option>
<option value="ROT18">ROT18</option>
<option value="ROT25">ROT25</option>
<option value="ROT30">ROT30</option>
<option value="XOR Pro">XOR Pro</option>
<option value="Affine Pro">Affine Pro</option>
<option value="Substitution Pro">Substitution Pro</option>
</select>
</div>
<div class="sub-container">
<label for="mode">Select action:</label>
<select id="mode">
<option value="encrypt">Encrypt</option>
<option value="decrypt">Decrypt</option>
</select>
</div>
<div class="sub-container">
<label for="useBaseEncoding">Base?</label>
<select id="useBaseEncoding">
<option value="false">No</option>
<option value="true">Yes</option>
</select>
</div>
<div class="sub-container">
<label for="baseCharset">Base Alphabet:</label>
<select id="baseCharset">
<option value="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567">Base32</option>
<option value="0123456789abcdefghijklmnopqrstuvwxyz">Base36</option>
<option value="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz2345789">Base58</option>
<option value="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789">Base62</option>
<option value="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=">Base64</option>
<option value="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@[]^_`{|}~">Base85 (ASCII85)</option>
<option value="0123456789abcdef">Base16 (Hexadecimal)</option>
<option value="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_">Base64 (Filename Safe)</option>
<option value="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.">Base64 (URL Safe)</option>
<option value="⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟">Base26 (Braille)</option>
<option value="._">Base2 (Morse Code)</option>
<option value="0123456789">Base9 (Numbers)</option>
<option value="+-">Base2 (+-)</option>
<option value="⇠⇡⇢⇣">Base2 (Arrows)</option>
<option value="ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ">Base24 (Greek Alphabet)</option>
<option value="АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ">Base33 (Cyrillic Alphabet)</option>
<option value="אבגדהוזחטיכלמנסעפצקרשת">Base22 (Hebrew Alphabet)</option>
<option value="أبجدهوزحطيكلمنسعفصقرشتثخذضظغ">Base28 (Arabic Alphabet)</option>
<option value="ᏣᎳᎩᎠᎡᎢᎣᎤᎥᎦᎧᎨᎩᎪᎫᎬᎭᎮᎯ">Base18 (Cherokee Alphabet)</option>
<option value="ሀሁሂሃሄህሆሇለሉሊላሌልሎ">Base13 (Ge'ez Alphabet)</option>
<option value="ᎠᎡᎢᎣᎤᎥᎦᎧᎨᎩᎪᎫᎬᎭᎮᎯ">Base17 (Old Italic Alphabet)</option>
<option value="ጰጱጲጳጴጵጶጷጸጹጺጻጼጽጾ">Base15 (Ethiopic Alphabet)</option>
<option value="ⰀⰁⰂⰃⰄⰅⰆⰇⰈⰉⰊⰋⰌⰍⰎⰏ">Base16 (Glagolitic Alphabet)</option>
<option value="ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋㅌㅍㅎ">Base14 (Korean Hangul)</option>
<option value="あいうえおかきくけこさしすせそ">Base15 (Japanese Hiragana)</option>
<option value="アイウエオカキクケコサシスセソ">Base15 (Japanese Katakana)</option>
<option value="ᚠᚢᚦᚨᚱᚲᚷᚹᚺᚾᛁᛃᛇᛈᛉᛋᛏᛒᛗᛚ">Base24 (Runes)</option>
<option value="〆ㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐㄑㄒㄓㄔㄕㄖㄗㄘㄙㄚㄛㄜㄝㄞㄟㄠㄡㄢㄣㄤㄥㄦ">Base37 (Chinese Zhuyin)</option>
<option value="ᎠᎡᎢᎣᎤᎥᎦᎧᎨᎩᎪᎫᎬᎭᎮᎯ">Base17 (Old Italic Alphabet)</option>
<option value="𐑖𐑗𐑘𐑙𐑚𐑛𐑜𐑝𐑞𐑟𐑠𐑡𐑢𐑣𐑤𐑥𐑦𐑧𐑨𐑩𐑪𐑫𐑬𐑭">Base24 (Shavian Alphabet)</option>
<option value="ᏐᏑᏒᏓᏕᏗᏘᏙᏚᏛ">Base10 (Cherokee Numerals)</option>
</select>
</div>
<div class="sub-container">
<button id="processBtn">Process</button>
<button id="swap">swap</button>
</div>
<div class="sub-container">
<label for="outputText">Result:</label>
<textarea id="outputText" rows="4" readonly></textarea>
<button onclick="document.getElementById('outputText').value='';">delete result</button>
</div>
<div id="note">
<p id="inputTextinfo"></p>
<p id="outputTextinfo"></p>
</div>
</div>
<script src="tughra.js"></script>
<script>
document.getElementById('file').addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
const reader = new FileReader();
// Define the onload event to handle the file data
reader.onload = function(event) {
const result = event.target.result; // Get the Data URL from the reader
document.getElementById('inputText').value = result; // Set the Data URL in the input field
};
// Read the file as a Data URL
reader.readAsDataURL(file);
}
});
document.getElementById('swap').addEventListener('click', function() {
const inputText = document.getElementById('inputText').value;
const outputText = document.getElementById('outputText').value;
// Swap text immediately to improve perceived performance
document.getElementById('inputText').value = outputText;
document.getElementById('outputText').value = inputText;
});
// Check if the browser supports Web Workers
if (window.Worker) {
const worker = new Worker('worker.js'); // Path to the worker script
document.getElementById('processBtn').addEventListener('click', function() {
const text = document.getElementById('inputText').value;
const cycles = parseInt(document.getElementById('cycles').value) || 5;
const baseCharset = document.getElementById('baseCharset').value;
const mode = document.getElementById('mode').value;
const useBaseEncoding = document.getElementById('useBaseEncoding').value === 'true';
const algorithm = document.getElementById('algorithm').value;
const encryptionKey = document.getElementById('encryptionKey').value;
// Post data to the worker
worker.postMessage({
text,
cycles,
baseCharset,
mode,
useBaseEncoding,
algorithm,
encryptionKey
});
// Listen for messages from the worker
worker.onmessage = function(e) {
const {
result,
error
} = e.data;
if (error) {
console.error("Error during encryption/decryption:", error);
} else {
document.getElementById('outputText').value = result;
getinfo();
}
};
});
} else {
alert("Web Workers are not supported in your browser.");
}
const tughra = new TughraLibrary();
function generateKey() {
const cycles = document.getElementById('keylength').value; // Get number of cycles
// Get the dropdown element
const groupDropdown = document.getElementById('unicodeGroupInput');
// Retrieve all selected options and join them with a comma separator
const groupNames = Array.from(groupDropdown.selectedOptions).map(option => option.value).join(', ');
console.log(groupNames); // This will print a comma-separated string of selected group names
// Generate the key with Tughra using the group names as a string
const key = tughra.generateKey(cycles, groupNames);
// Display the key in the input field
document.getElementById('encryptionKey').value = key.join('');
}
document.addEventListener('DOMContentLoaded', function() {
// Assuming you have already created an instance of your class
const tughra = new TughraLibrary(); // Adjust to your class instance
// Fetch the available Unicode groups
const unicodeGroups = tughra.getUnicodeGroups();
// Get the dropdown element where the options will be added
const groupDropdown = document.getElementById('unicodeGroupInput');
// Clear previous options (if any) to avoid duplicates
groupDropdown.innerHTML = '';
// Get the names of all groups and join them into a comma-separated string
const allGroupNames = unicodeGroups.map(group => group.name).join(', ');
// Add the "Select All" option at the top
const selectAllOption = document.createElement('option');
selectAllOption.value = 'all'; // Set a unique value for "All"
selectAllOption.textContent = 'All Unicode Groups'; // Displayed text
groupDropdown.appendChild(selectAllOption); // Add to dropdown
// Populate the dropdown with individual groups
unicodeGroups.forEach(group => {
const option = document.createElement('option');
option.value = group.name;
option.textContent = group.name;
// Optionally select specific groups by default
if (group.name === 'Uppercase English' || group.name === 'Lowercase English' || group.name === 'Numbers') {
option.selected = true;
}
groupDropdown.appendChild(option); // Add to dropdown
});
document.getElementById('unicodeGroupInput').addEventListener('change', () => {
const selectedOptions = Array.from(document.getElementById('unicodeGroupInput').selectedOptions).map(option => option.value);
console.log(selectedOptions);
});
});
function getinfo() {
const resultText = document.getElementById('outputText').value;
const text = document.getElementById('inputText').value;
document.getElementById('note').classList.add('note');
const inputstats = tughra._calculateStats(text);
document.getElementById('inputTextinfo').innerHTML =
'Input ⇢ <br>language: ' + tughra.detectLanguage(text) + ', <br>Size: ' + tughra._formatSize(inputstats.size) + ',\n' +
'<br>Characters: ' + inputstats.characters + ',\n' +
'<br>Words: ' + inputstats.words + ',\n' +
'<br>Lines: ' + inputstats.lines + ',\n' +
'<br>Type: ' + inputstats.type + ',\n' +
'<br>Is Blob: ' + (inputstats.isBlob ? 'Yes' : 'No') + ',\n' +
'<br>Is Data URI: ' + (inputstats.isDataURI ? 'Yes' : 'No');
const outputstats = tughra._calculateStats(resultText);
document.getElementById('outputTextinfo').innerHTML =
'Output ⇢ <br>language: ' + tughra.detectLanguage(resultText) + ', <br>Size: ' + tughra._formatSize(outputstats.size) + ',\n' +
'<br>Characters: ' + outputstats.characters + ',\n' +
'<br>Words: ' + outputstats.words + ',\n' +
'<br>Lines: ' + outputstats.lines + ',\n' +
'<br>Type: ' + outputstats.type + ',\n' +
'<br>Is Blob: ' + (outputstats.isBlob ? 'Yes' : 'No') + ',\n' +
'<br>Is Data URI: ' + (outputstats.isDataURI ? 'Yes' : 'No');
}
</script>
</body>
</html>