-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbase64-decoder.html
More file actions
404 lines (365 loc) · 14 KB
/
Copy pathbase64-decoder.html
File metadata and controls
404 lines (365 loc) · 14 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Base64 Decoder — DevDunia</title>
<meta name="description" content="Decode Base64 encoded data back to original format. Free online Base64 decoder tool for developers.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://devdunia.com/base64-decoder.html">
<meta property="og:title" content="Base64 Decoder — DevDunia">
<meta property="og:description" content="Decode Base64 encoded data back to original format. Free online Base64 decoder tool.">
<meta property="og:image" content="https://devdunia.com/images/logo.png">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="stylesheet" href="css/comic.css">
<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>
/* ---- TODO migrate: page-specific overrides, not yet centralized in css/comic.css ---- */
.hero-text h1 {
font-family: 'Bangers', cursive;
font-size: 2.8rem;
letter-spacing: 2px;
color: var(--blue);
-webkit-text-stroke: 1px var(--ink);
text-shadow: 4px 4px 0 var(--ink);
line-height: 1;
text-transform: uppercase;
}
.comic-textarea:focus { border-color: var(--blue); box-shadow: inset 3px 3px 0 rgba(29,111,184,.1); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-purple { background: var(--purple); color: #fff; }
/* ── SUCCESS BUBBLE ── */
.success-bubble {
display: none;
position: relative;
background: #f0fff4;
border: 3px solid var(--green);
border-radius: 14px;
padding: 10px 14px;
margin-top: 12px;
font-size: .88rem;
color: var(--ink);
}
.success-bubble.show { display: block; }
/* ── STATS ROW ── */
.stats-row {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 14px;
}
.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; }
.stat-chip.chip-yellow { background: var(--yellow); color: var(--ink); }
/* ── EXAMPLES GRID ── */
.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-encoded {
font-family: 'Space Mono', monospace;
font-size: .68rem;
color: var(--blue);
word-break: break-all;
margin-bottom: 2px;
}
.example-arrow {
font-size: .75rem;
color: var(--ink);
opacity: .55;
}
/* ── DIVIDER ── */
.divider {
border: none;
border-top: 3px solid var(--ink);
margin: 16px 0;
}
/* ── MOBILE ── */
@media (max-width: 600px) {
.examples-grid { grid-template-columns: 1fr; }
.hero { flex-direction: column; gap: 10px; }
.hero-text h1 { font-size: 2rem; }
.stats-row { gap: 6px; }
}
</style>
</head>
<body>
<div class="paper-overlay"></div>
<div data-masthead></div>
<div class="page-wrap">
<div data-tool-hero
data-title="Base64 Decoder"
data-chapter="05"
data-category="Encoders & Decoders"
data-icon="🔓"
data-desc="Paste any Base64-encoded string and crack it open instantly. No server, no tracking — pure client-side decoding right in your browser!"
data-color="green"
data-badges="CLIENT-SIDE,NO SERVER,FREE,INSTANT"
data-badge-colors="blue,green,yellow,red">
</div>
<!-- MASTHEAD -->
<!-- HERO -->
<!-- INPUT PANEL -->
<div class="panel">
<div class="panel-header">
📥 PASTE YOUR BASE64 HERE
<span class="panel-tag">INPUT</span>
</div>
<div class="panel-body">
<div class="section-label">Base64 Encoded Data</div>
<textarea id="base64-input" class="comic-textarea" rows="6"
placeholder="Paste Base64 encoded data here... e.g. SGVsbG8gV29ybGQ="></textarea>
<div class="btn-row">
<button id="decode-btn" class="btn btn-primary">⚡ Decode!</button>
<button id="encode-btn" class="btn btn-neutral">🔄 Encode Instead</button>
<button id="clear-btn" class="btn btn-danger">🗑 Clear</button>
</div>
<div id="error-bubble" class="error-bubble">
💥 <span id="error-msg">Invalid Base64!</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 Text</div>
<div class="output-wrap">
<textarea id="base64-output" class="comic-textarea" rows="7" readonly></textarea>
<button id="copy-btn" class="copy-btn">📋 COPY</button>
</div>
<!-- STATS -->
<div class="stats-row" id="stats-row">
<div class="stat-chip chip-blue">
<span class="stat-label">B64 SIZE</span>
<span id="stat-b64-size">—</span>
</div>
<div class="stat-chip chip-green">
<span class="stat-label">DECODED</span>
<span id="stat-dec-size">—</span>
</div>
<div class="stat-chip chip-purple">
<span class="stat-label">OVERHEAD</span>
<span id="stat-overhead">—</span>
</div>
<div class="stat-chip chip-yellow">
<span class="stat-label">PADDING</span>
<span id="stat-padding">—</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="SGVsbG8gV29ybGQ=">
<div class="example-title" style="color:var(--blue);">Simple Text</div>
<div class="example-encoded">SGVsbG8gV29ybGQ=</div>
<div class="example-arrow">↓ "Hello World"</div>
</div>
<div class="example-card" data-encoded="eyJuYW1lIjoiQWxpIiwidG9vbCI6IkRldk51bmlhIn0=">
<div class="example-title" style="color:var(--green);">JSON Object</div>
<div class="example-encoded">eyJuYW1lIjoiQWxpIiwidG9vbCI6IkRldk51bmlhIn0=</div>
<div class="example-arrow">↓ {"name":"Ali",...}</div>
</div>
<div class="example-card" data-encoded="aHR0cHM6Ly9kZXZkdW5pYS5jb20=">
<div class="example-title" style="color:var(--purple);">URL</div>
<div class="example-encoded">aHR0cHM6Ly9kZXZkdW5pYS5jb20=</div>
<div class="example-arrow">↓ https://devdunia.com</div>
</div>
<div class="example-card" data-encoded="U2VjcmV0TWVzc2FnZTEyMw==">
<div class="example-title" style="color:var(--red);">Hidden Message</div>
<div class="example-encoded">U2VjcmV0TWVzc2FnZTEyMw==</div>
<div class="example-arrow">↓ SecretMessage123</div>
</div>
</div>
</div>
</div>
<!-- HOW IT WORKS -->
<div class="panel">
<div class="panel-header">
🧠 HOW BASE64 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(--blue);">1</div>
<p>Every character in your text becomes its <strong>ASCII number</strong> (e.g. 'H' → 72, 'i' → 105).</p>
</div>
<div class="how-step">
<div class="step-dot" style="background:var(--green);">2</div>
<p>Those bytes are grouped into <strong>3-byte chunks</strong> (24 bits) then split into <strong>four 6-bit groups</strong>.</p>
</div>
<div class="how-step">
<div class="step-dot" style="background:var(--orange);">3</div>
<p>Each 6-bit value maps to one of <strong>64 characters</strong>: A-Z, a-z, 0-9, +, /. That's where the name comes from!</p>
</div>
<div class="how-step">
<div class="step-dot" style="background:var(--purple);">4</div>
<p><code>=</code> padding is added to make the output length a multiple of 4. This decoder strips it automatically.</p>
</div>
<div class="how-step">
<div class="step-dot" style="background:var(--red);">5</div>
<p>Decoding is the exact reverse — Base64 chars → 6-bit groups → bytes → original text. <strong>~33% size overhead</strong> is the trade-off for safe ASCII transport.</p>
</div>
</div>
</div>
</div>
</div><!-- /page-wrap -->
<script>
(function() {
var inputEl = document.getElementById('base64-input');
var outputEl = document.getElementById('base64-output');
var decodeBtn = document.getElementById('decode-btn');
var encodeBtn = document.getElementById('encode-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 statB64 = document.getElementById('stat-b64-size');
var statDec = document.getElementById('stat-dec-size');
var statOver = document.getElementById('stat-overhead');
var statPad = document.getElementById('stat-padding');
var encodeMode = false;
function showError(msg) {
errMsg.textContent = msg;
errBubble.classList.add('show');
}
function hideError() { errBubble.classList.remove('show'); }
function showOutput(text) {
outputEl.value = text;
outPanel.style.display = 'block';
hideError();
}
function formatBytes(n) {
if (n === 0) return '0 B';
if (n < 1024) return n + ' B';
return (n / 1024).toFixed(1) + ' KB';
}
function isValidBase64(str) {
try { return btoa(atob(str)) === str; } catch(e) { return false; }
}
function decode() {
var raw = inputEl.value.trim();
if (!raw) { showError('Please paste some Base64 data first!'); return; }
var clean = raw.replace(/\s/g, '');
if (!isValidBase64(clean)) { showError('That does not look like valid Base64. Check for typos!'); outPanel.style.display='none'; return; }
var decoded;
try { decoded = atob(clean); } catch(e) { showError('Decode failed: ' + e.message); return; }
showOutput(decoded);
var b64Bytes = new Blob([clean]).size;
var decBytes = new Blob([decoded]).size;
var overhead = b64Bytes > 0 ? (((b64Bytes - decBytes) / b64Bytes) * 100).toFixed(1) : '0';
var padMatch = clean.match(/=+$/);
var padCount = padMatch ? padMatch[0].length : 0;
statB64.textContent = formatBytes(b64Bytes);
statDec.textContent = formatBytes(decBytes);
statOver.textContent = overhead + '%';
statPad.textContent = padCount + ' chars';
}
function encode() {
var raw = inputEl.value;
if (!raw) { showError('Please type some text to encode!'); return; }
try {
var encoded = btoa(unescape(encodeURIComponent(raw)));
showOutput(encoded);
var rawBytes = new Blob([raw]).size;
var encBytes = new Blob([encoded]).size;
statB64.textContent = formatBytes(encBytes);
statDec.textContent = formatBytes(rawBytes);
statOver.textContent = rawBytes > 0 ? (((encBytes - rawBytes) / rawBytes) * 100).toFixed(1) + '%' : '0%';
var padMatch = encoded.match(/=+$/);
statPad.textContent = (padMatch ? padMatch[0].length : 0) + ' chars';
} catch(e) { showError('Encode failed: ' + e.message); }
}
decodeBtn.addEventListener('click', function() {
if (encodeMode) { decode.call = null; encode(); } else { decode(); }
});
encodeBtn.addEventListener('click', function() {
encodeMode = !encodeMode;
if (encodeMode) {
decodeBtn.textContent = '⚡ Encode!';
encodeBtn.textContent = 'ὐ4 Decode Instead';
inputEl.placeholder = 'Type plain text here to encode to Base64...';
} else {
decodeBtn.textContent = '⚡ Decode!';
encodeBtn.textContent = 'ὐ4 Encode Instead';
inputEl.placeholder = 'Paste Base64 encoded data here...';
}
outPanel.style.display = 'none';
hideError();
});
clearBtn.addEventListener('click', function() {
inputEl.value = '';
outputEl.value = '';
outPanel.style.display = 'none';
hideError();
encodeMode = false;
decodeBtn.textContent = '⚡ Decode!';
encodeBtn.textContent = 'ὐ4 Encode Instead';
inputEl.placeholder = 'Paste Base64 encoded data here... e.g. SGVsbG8gV29ybGQ=';
});
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;
encodeMode = false;
decodeBtn.textContent = '⚡ Decode!';
decode();
});
}
// Keyboard shortcut
inputEl.addEventListener('keydown', function(e) {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { encodeMode ? encode() : decode(); }
});
// Preload
inputEl.value = 'SGVsbG8gRnJvbSBEZXZEdW5pYSE=';
})();
</script>
<script src="masthead.js"></script>
<script src="hero-banner.js"></script>
<script src="author-card.js"></script>
</body>
</html>