-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbase62-decoder.html
More file actions
620 lines (552 loc) · 17.6 KB
/
Copy pathbase62-decoder.html
File metadata and controls
620 lines (552 loc) · 17.6 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Base62 Decoder — DevDunia Comics</title>
<meta name="description" content="Decode Base62 encoded data back to original format. Free online Base62 decoder tool for developers.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://devdunia.com/base62-decoder.html">
<meta property="og:title" content="Base62 Decoder — DevDunia Comics">
<meta property="og:description" content="Decode Base62 encoded data back to original format. Free online Base62 decoder tool for developers.">
<meta property="og:image" content="https://devdunia.com/images/logo.png">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Bangers&family=Comic+Neue:wght@400;700&family=Space+Mono:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--ink: #1a1410;
--paper: #fdf3e3;
--paper2: #fbe9cc;
--red: #e63946;
--blue: #1d6fb8;
--yellow: #ffd23f;
--green: #3fa34d;
--pink: #ff6b9d;
--purple: #8a4fff;
--orange: #ff8c42;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Comic Neue', cursive;
font-weight: 400;
color: var(--ink);
background-color: var(--paper);
background-image: radial-gradient(var(--ink) 0.5px, transparent 0.6px);
background-size: 14px 14px;
background-attachment: fixed;
min-height: 100vh;
}
.paper-overlay {
position: fixed;
inset: 0;
background: rgba(253,243,227,.78);
pointer-events: none;
z-index: 0;
}
.page-wrap {
position: relative;
z-index: 1;
max-width: 1240px;
margin: 0 auto;
padding: 20px 32px 60px;
}
.hero {
display: flex;
align-items: flex-start;
gap: 20px;
background: var(--paper2);
border: 4px solid var(--ink);
border-radius: 6px;
box-shadow: 7px 7px 0 var(--ink);
padding: 20px 24px;
margin-bottom: 28px;
transform: rotate(-0.4deg);
}
.hero-icon {
font-size: 3rem;
line-height: 1;
flex-shrink: 0;
filter: drop-shadow(3px 3px 0 var(--ink));
}
.hero-text h1 {
font-family: 'Bangers', cursive;
font-size: 2.8rem;
letter-spacing: 2px;
color: var(--purple);
-webkit-text-stroke: 1px var(--ink);
text-shadow: 4px 4px 0 var(--ink);
line-height: 1;
text-transform: uppercase;
}
.hero-text p {
font-size: .95rem;
margin-top: 6px;
line-height: 1.5;
max-width: 480px;
}
.hero-badges {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 10px;
}
.badge {
font-family: 'Space Mono', monospace;
font-size: .65rem;
font-weight: 700;
padding: 3px 8px;
border: 2px solid var(--ink);
border-radius: 4px;
box-shadow: 2px 2px 0 var(--ink);
}
.badge-blue { background: var(--blue); color: #fff; }
.badge-green { background: var(--green); color: #fff; }
.badge-yellow { background: var(--yellow); color: var(--ink); }
.badge-red { background: var(--red); color: #fff; }
.badge-purple { background: var(--purple); color: #fff; }
.panel {
background: var(--paper);
border: 4px solid var(--ink);
border-radius: 6px;
box-shadow: 7px 7px 0 var(--ink);
overflow: hidden;
margin-bottom: 22px;
}
.panel-header {
background: var(--ink);
color: var(--yellow);
font-family: 'Bangers', cursive;
font-size: 1.2rem;
letter-spacing: 2px;
padding: 8px 16px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.panel-header .panel-tag {
font-family: 'Space Mono', monospace;
font-size: .65rem;
font-weight: 700;
background: var(--yellow);
color: var(--ink);
padding: 2px 7px;
border-radius: 3px;
}
.panel-body { padding: 18px 20px; }
.comic-textarea {
width: 100%;
background: #fff;
border: 3px solid var(--ink);
border-radius: 6px;
padding: 12px 14px;
font-family: 'Space Mono', monospace;
font-size: .82rem;
color: var(--ink);
line-height: 1.6;
resize: vertical;
min-height: 130px;
box-shadow: inset 3px 3px 0 rgba(0,0,0,.06);
outline: none;
transition: border-color .15s;
}
.comic-textarea:focus { border-color: var(--purple); box-shadow: inset 3px 3px 0 rgba(138,79,255,.1); }
.comic-textarea::placeholder { color: #aaa; font-style: italic; }
.comic-textarea[readonly] { background: var(--paper2); cursor: default; }
.btn-row {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 14px;
}
.btn {
font-family: 'Bangers', cursive;
font-size: 1.1rem;
letter-spacing: 1px;
border: 3px solid var(--ink);
border-radius: 6px;
padding: 8px 20px;
cursor: pointer;
box-shadow: 4px 4px 0 var(--ink);
transition: transform .1s, box-shadow .1s;
text-transform: uppercase;
}
.btn:active { transform: translate(2px,2px); box-shadow: 2px 2px 0 var(--ink); }
.btn-primary { background: var(--purple); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.error-bubble {
display: none;
position: relative;
background: #fff0f0;
border: 3px solid var(--red);
border-radius: 14px;
padding: 10px 14px;
margin-top: 12px;
font-size: .9rem;
font-weight: 700;
color: var(--red);
}
.error-bubble::before {
content: '';
position: absolute;
top: -16px;
left: 22px;
border-width: 0 10px 16px;
border-style: solid;
border-color: transparent transparent var(--red);
}
.error-bubble::after {
content: '';
position: absolute;
top: -11px;
left: 24px;
border-width: 0 8px 12px;
border-style: solid;
border-color: transparent transparent #fff0f0;
}
.error-bubble.show { display: block; }
.output-wrap { position: relative; }
.copy-btn {
position: absolute;
top: 8px;
right: 8px;
font-family: 'Bangers', cursive;
font-size: .95rem;
letter-spacing: 1px;
background: var(--ink);
color: var(--yellow);
border: 2px solid var(--ink);
border-radius: 4px;
padding: 3px 10px;
cursor: pointer;
box-shadow: 2px 2px 0 rgba(0,0,0,.4);
transition: transform .1s, box-shadow .1s;
}
.copy-btn:active { transform: translate(1px,1px); box-shadow: 1px 1px 0 rgba(0,0,0,.4); }
.stats-row {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 14px;
}
.stat-chip {
font-family: 'Space Mono', monospace;
font-size: .72rem;
font-weight: 700;
padding: 4px 10px;
border: 2px solid var(--ink);
border-radius: 4px;
box-shadow: 2px 2px 0 var(--ink);
display: flex;
align-items: center;
gap: 5px;
}
.stat-chip .stat-label { opacity: .65; font-weight: 400; }
.stat-chip.chip-blue { background: var(--blue); color: #fff; }
.stat-chip.chip-green { background: var(--green); color: #fff; }
.stat-chip.chip-purple { background: var(--purple); color: #fff; }
.section-label {
font-family: 'Bangers', cursive;
font-size: .95rem;
letter-spacing: 1px;
color: var(--ink);
margin-bottom: 6px;
text-transform: uppercase;
}
.examples-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.example-card {
background: var(--paper2);
border: 3px solid var(--ink);
border-radius: 6px;
box-shadow: 4px 4px 0 var(--ink);
padding: 10px 12px;
cursor: pointer;
transition: transform .1s, box-shadow .1s;
}
.example-card:hover { transform: translate(-2px,-2px); box-shadow: 6px 6px 0 var(--ink); }
.example-card:active { transform: translate(1px,1px); box-shadow: 2px 2px 0 var(--ink); }
.example-title {
font-family: 'Bangers', cursive;
font-size: 1rem;
letter-spacing: 1px;
margin-bottom: 4px;
}
.example-preview {
font-family: 'Space Mono', monospace;
font-size: .68rem;
color: var(--purple);
word-break: break-all;
margin-bottom: 2px;
}
.example-arrow {
font-size: .75rem;
color: var(--ink);
opacity: .55;
}
.how-steps { display: flex; flex-direction: column; gap: 10px; }
.how-step { display: flex; align-items: flex-start; gap: 12px; }
.step-dot {
width: 28px;
height: 28px;
border-radius: 50%;
border: 3px solid var(--ink);
display: flex;
align-items: center;
justify-content: center;
font-family: 'Bangers', cursive;
font-size: 1rem;
color: #fff;
flex-shrink: 0;
box-shadow: 2px 2px 0 var(--ink);
}
.how-step p { font-size: .88rem; line-height: 1.5; padding-top: 2px; }
.how-step code {
font-family: 'Space Mono', monospace;
font-size: .75rem;
background: var(--ink);
color: var(--yellow);
padding: 1px 5px;
border-radius: 3px;
}
@media (max-width: 600px) {
.examples-grid { grid-template-columns: 1fr; }
.hero { flex-direction: column; gap: 10px; }
.hero-text h1 { font-size: 2rem; }
}
</style>
</head>
<body>
<div class="paper-overlay"></div>
<div data-masthead></div>
<div class="page-wrap">
<div data-tool-hero
data-title="Base62 Decoder"
data-chapter="03"
data-category="Encoders & Decoders"
data-icon="🔓"
data-desc="Crack open Base62-encoded strings and reveal the original text. Reverse the encoding process instantly — pure client-side magic, no server required!"
data-color="green"
data-badges="DECODE,CLIENT-SIDE,NO SERVER,FREE"
data-badge-colors="purple,blue,green,yellow">
</div>
<!-- MASTHEAD -->
<!-- HERO -->
<!-- INPUT PANEL -->
<div class="panel">
<div class="panel-header">
📥 PASTE YOUR BASE62 HERE
<span class="panel-tag">INPUT</span>
</div>
<div class="panel-body">
<div class="section-label">Base62 Encoded String</div>
<textarea id="base62-input" class="comic-textarea" rows="4"
placeholder="Enter Base62 encoded string to decode..."></textarea>
<div class="btn-row">
<button id="decode-btn" class="btn btn-primary">⚡ Decode from Base62!</button>
<button id="clear-btn" class="btn btn-danger">🗑 Clear</button>
</div>
<div id="error-bubble" class="error-bubble">
💥 <span id="error-msg">Invalid Base62 string!</span>
</div>
</div>
</div>
<!-- OUTPUT PANEL -->
<div class="panel" id="output-panel" style="display:none;">
<div class="panel-header">
📤 DECODED OUTPUT
<span class="panel-tag">OUTPUT</span>
</div>
<div class="panel-body">
<div class="section-label">Decoded Result</div>
<div class="output-wrap">
<textarea id="base62-output" class="comic-textarea" rows="6" readonly></textarea>
<button id="copy-btn" class="copy-btn">📋 COPY</button>
</div>
<div class="stats-row">
<div class="stat-chip chip-blue">
<span class="stat-label">BASE62 SIZE</span>
<span id="stat-b62">—</span>
</div>
<div class="stat-chip chip-green">
<span class="stat-label">DECODED</span>
<span id="stat-decoded">—</span>
</div>
<div class="stat-chip chip-purple">
<span class="stat-label">COMPRESSION</span>
<span id="stat-compression">—</span>
</div>
</div>
</div>
</div>
<!-- EXAMPLES PANEL -->
<div class="panel">
<div class="panel-header">
📚 TRY AN EXAMPLE — CLICK TO LOAD!
<span class="panel-tag">EXAMPLES</span>
</div>
<div class="panel-body">
<div class="examples-grid">
<div class="example-card" data-encoded="AKRfxYADYEmO3sJOfsNFm2iaVur">
<div class="example-title" style="color:var(--blue);">Hello from DevDunia!</div>
<div class="example-preview">AKRfxYADYEmO3sJOfsNFm2iaVur</div>
<div class="example-arrow">↓ Decode to reveal text</div>
</div>
<div class="example-card" data-encoded="T8dgcjAQ">
<div class="example-title" style="color:var(--green);">Hello</div>
<div class="example-preview">T8dgcjAQ</div>
<div class="example-arrow">↓ Decode to reveal text</div>
</div>
<div class="example-card" data-encoded="1wgp">
<div class="example-title" style="color:var(--purple);">Test</div>
<div class="example-preview">1wgp</div>
<div class="example-arrow">↓ Decode to reveal text</div>
</div>
<div class="example-card" data-encoded="0">
<div class="example-title" style="color:var(--red);">Zero Byte</div>
<div class="example-preview">0</div>
<div class="example-arrow">↓ Leading zero byte</div>
</div>
</div>
</div>
</div>
<!-- HOW IT WORKS -->
<div class="panel">
<div class="panel-header">
🧠 HOW BASE62 DECODING WORKS
<span class="panel-tag">EXPLAINER</span>
</div>
<div class="panel-body">
<div class="how-steps">
<div class="how-step">
<div class="step-dot" style="background:var(--purple);">1</div>
<p>Each character in the Base62 string maps to a number: <code>0–9 → 0–9</code>, <code>A–Z → 10–35</code>, <code>a–z → 36–61</code>.</p>
</div>
<div class="how-step">
<div class="step-dot" style="background:var(--blue);">2</div>
<p>Characters are combined into one <strong>BigInt number</strong> by repeatedly multiplying by 62 and adding each digit's value (base-62 to decimal).</p>
</div>
<div class="how-step">
<div class="step-dot" style="background:var(--green);">3</div>
<p>The big number is converted back to <strong>bytes</strong> by taking mod 256 and dividing — reversing the encoding's base-256 process.</p>
</div>
<div class="how-step">
<div class="step-dot" style="background:var(--orange);">4</div>
<p>Bytes are decoded as <strong>UTF-8 text</strong> using TextDecoder. If it's not valid UTF-8, the raw hex values are shown instead.</p>
</div>
</div>
</div>
</div>
</div><!-- /page-wrap -->
<script>
(function() {
var inputEl = document.getElementById('base62-input');
var outputEl = document.getElementById('base62-output');
var decodeBtn = document.getElementById('decode-btn');
var clearBtn = document.getElementById('clear-btn');
var copyBtn = document.getElementById('copy-btn');
var outPanel = document.getElementById('output-panel');
var errBubble = document.getElementById('error-bubble');
var errMsg = document.getElementById('error-msg');
var statB62 = document.getElementById('stat-b62');
var statDec = document.getElementById('stat-decoded');
var statComp = document.getElementById('stat-compression');
var ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
function showError(msg) {
errMsg.textContent = msg;
errBubble.classList.add('show');
outPanel.style.display = 'none';
}
function hideError() { errBubble.classList.remove('show'); }
function formatBytes(n) {
if (n === 0) return '0 B';
if (n < 1024) return n + ' B';
return (n / 1024).toFixed(1) + ' KB';
}
function isValidBase62(str) {
for (var i = 0; i < str.length; i++) {
if (ALPHABET.indexOf(str[i]) === -1) return false;
}
return true;
}
function decodeFromBase62(input) {
if (!input || input === ALPHABET[0]) return '';
var leadingZeros = 0;
for (var i = 0; i < input.length && input[i] === ALPHABET[0]; i++) { leadingZeros++; }
var num = 0n;
for (var j = 0; j < input.length; j++) {
var idx = ALPHABET.indexOf(input[j]);
if (idx === -1) throw new Error('Invalid Base62 character: ' + input[j]);
num = num * 62n + BigInt(idx);
}
var bytes = [];
while (num > 0n) {
bytes.unshift(Number(num % 256n));
num = num / 256n;
}
var result = new Uint8Array(leadingZeros + bytes.length);
for (var k = 0; k < leadingZeros; k++) { result[k] = 0; }
for (var l = 0; l < bytes.length; l++) { result[leadingZeros + l] = bytes[l]; }
try {
return new TextDecoder().decode(result);
} catch(e) {
return Array.from(result).map(function(b) { return b.toString(16).padStart(2, '0'); }).join(' ');
}
}
function doDecode() {
var input = inputEl.value.trim();
if (!input) { showError('Please enter a Base62 string to decode!'); return; }
if (!isValidBase62(input)) { showError('Invalid Base62 string. Allowed characters: 0–9, A–Z, a–z'); return; }
try {
var decoded = decodeFromBase62(input);
outputEl.value = decoded;
outPanel.style.display = 'block';
hideError();
var encBytes = new Blob([input]).size;
var decBytes = new Blob([decoded]).size;
statB62.textContent = formatBytes(encBytes);
statDec.textContent = formatBytes(decBytes);
statComp.textContent = decBytes === 0 ? '0%' : (((encBytes - decBytes) / decBytes) * 100).toFixed(1) + '%';
} catch(e) {
showError('Error decoding: ' + e.message);
}
}
decodeBtn.addEventListener('click', doDecode);
clearBtn.addEventListener('click', function() {
inputEl.value = '';
outputEl.value = '';
outPanel.style.display = 'none';
hideError();
});
copyBtn.addEventListener('click', function() {
outputEl.select();
try { document.execCommand('copy'); } catch(e) {}
if (navigator.clipboard) navigator.clipboard.writeText(outputEl.value).catch(function(){});
var orig = copyBtn.textContent;
copyBtn.textContent = '✔ COPIED!';
copyBtn.style.background = 'var(--green)';
setTimeout(function() { copyBtn.textContent = orig; copyBtn.style.background = 'var(--ink)'; }, 1800);
});
// Example cards
var cards = document.querySelectorAll('.example-card');
for (var i = 0; i < cards.length; i++) {
cards[i].addEventListener('click', function() {
inputEl.value = this.dataset.encoded;
doDecode();
});
}
inputEl.addEventListener('keydown', function(e) {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { doDecode(); }
});
// Preload
inputEl.value = 'AKRfxYADYEmO3sJOfsNFm2iaVur';
})();
</script>
<script src="masthead.js"></script>
<script src="hero-banner.js"></script>
<script src="author-card.js"></script>
</body>
</html>