280 lines
8.7 KiB
HTML
280 lines
8.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>String Tools</title>
|
|
<style>
|
|
* {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
}
|
|
body {
|
|
background-color: #f4f6f8;
|
|
color: #333;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
.container {
|
|
background: #ffffff;
|
|
border-radius: 12px;
|
|
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
|
|
padding: 30px;
|
|
width: 100%;
|
|
max-width: 650px;
|
|
}
|
|
h2 {
|
|
margin-bottom: 20px;
|
|
font-size: 1.5rem;
|
|
text-align: center;
|
|
}
|
|
.input-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
label {
|
|
display: block;
|
|
font-weight: 600;
|
|
font-size: 0.9rem;
|
|
margin-bottom: 6px;
|
|
}
|
|
textarea {
|
|
width: 100%;
|
|
height: 100px;
|
|
padding: 12px;
|
|
border: 1px solid #ccc;
|
|
border-radius: 6px;
|
|
font-size: 0.95rem;
|
|
resize: vertical;
|
|
background-color: #fafafa;
|
|
}
|
|
textarea:focus {
|
|
outline: none;
|
|
border-color: #0066ff;
|
|
background-color: #fff;
|
|
}
|
|
.section-header {
|
|
font-size: 0.85rem;
|
|
font-weight: 700;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
color: #0066ff;
|
|
margin: 20px 0 10px 0;
|
|
padding-bottom: 4px;
|
|
border-bottom: 2px solid #e1effe;
|
|
}
|
|
.output-card {
|
|
background-color: #f8f9fa;
|
|
border: 1px solid #e9ecef;
|
|
border-radius: 6px;
|
|
padding: 12px;
|
|
margin-bottom: 12px;
|
|
}
|
|
.output-card.hidden {
|
|
display: none;
|
|
}
|
|
.output-card.error {
|
|
border-color: #ffc9c9;
|
|
background-color: #fff5f5;
|
|
}
|
|
.output-card .title {
|
|
font-size: 0.8rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
color: #6c757d;
|
|
margin-bottom: 4px;
|
|
font-weight: 700;
|
|
}
|
|
.output-card .value {
|
|
font-family: monospace;
|
|
font-size: 0.95rem;
|
|
word-break: break-all;
|
|
white-space: pre-wrap;
|
|
color: #212529;
|
|
}
|
|
.value.error-text {
|
|
color: #d9534f;
|
|
font-style: italic;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
<h2>String Tools</h2>
|
|
|
|
<div class="input-group">
|
|
<label for="strInput">Enter your string below:</label>
|
|
<textarea id="strInput" placeholder="Type or paste something here..."></textarea>
|
|
</div>
|
|
|
|
<div class="section-header">String Transformations</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">Character Count (Length)</div>
|
|
<div class="value" id="outLength">0</div>
|
|
</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">Uppercase</div>
|
|
<div class="value" id="outUpper">---</div>
|
|
</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">Lowercase</div>
|
|
<div class="value" id="outLower">---</div>
|
|
</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">URL Encoded</div>
|
|
<div class="value" id="outEncoded">---</div>
|
|
</div>
|
|
|
|
<div class="output-card" id="urlDecodedCard">
|
|
<div class="title">URL Decoded</div>
|
|
<div class="value" id="outDecoded">---</div>
|
|
</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">Base64 Encoded</div>
|
|
<div class="value" id="outB64Enc">---</div>
|
|
</div>
|
|
|
|
<div class="output-card hidden" id="b64DecCard">
|
|
<div class="title">Base64 Decoded</div>
|
|
<div class="value" id="outB64Dec">---</div>
|
|
</div>
|
|
|
|
<div class="section-header">Hashes</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">SHA-1</div>
|
|
<div class="value" id="outSha1">---</div>
|
|
</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">SHA-256</div>
|
|
<div class="value" id="outSha256">---</div>
|
|
</div>
|
|
|
|
<div class="output-card">
|
|
<div class="title">SHA-512</div>
|
|
<div class="value" id="outSha512">---</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const strInput = document.getElementById('strInput');
|
|
const outLength = document.getElementById('outLength');
|
|
const outUpper = document.getElementById('outUpper');
|
|
const outLower = document.getElementById('outLower');
|
|
const outEncoded = document.getElementById('outEncoded');
|
|
const outDecoded = document.getElementById('outDecoded');
|
|
const urlDecodedCard = document.getElementById('urlDecodedCard');
|
|
|
|
const outB64Enc = document.getElementById('outB64Enc');
|
|
const outB64Dec = document.getElementById('outB64Dec');
|
|
const b64DecCard = document.getElementById('b64DecCard');
|
|
|
|
const outSha1 = document.getElementById('outSha1');
|
|
const outSha256 = document.getElementById('outSha256');
|
|
const outSha512 = document.getElementById('outSha512');
|
|
|
|
// Safe Unicode Base64 Helper
|
|
function utf8ToBase64(str) {
|
|
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => {
|
|
return String.fromCharCode('0x' + p1);
|
|
}));
|
|
}
|
|
|
|
function base64ToUtf8(str) {
|
|
return decodeURIComponent(atob(str).split('').map((c) => {
|
|
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
}).join(''));
|
|
}
|
|
|
|
// Helper function to calculate Web Crypto hashes
|
|
async function computeHash(algo, text) {
|
|
if (!text) return '---';
|
|
const msgUint8 = new TextEncoder().encode(text);
|
|
const hashBuffer = await crypto.subtle.digest(algo, msgUint8);
|
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
}
|
|
|
|
strInput.addEventListener('input', async () => {
|
|
const val = strInput.value;
|
|
|
|
if (val.length === 0) {
|
|
outLength.textContent = '0';
|
|
outUpper.textContent = '---';
|
|
outLower.textContent = '---';
|
|
outEncoded.textContent = '---';
|
|
outDecoded.textContent = '---';
|
|
outB64Enc.textContent = '---';
|
|
outB64Dec.textContent = '---';
|
|
outSha1.textContent = '---';
|
|
outSha256.textContent = '---';
|
|
outSha512.textContent = '---';
|
|
|
|
urlDecodedCard.classList.remove('error');
|
|
b64DecCard.classList.add('hidden');
|
|
return;
|
|
}
|
|
|
|
// Basic Transformations
|
|
outLength.textContent = val.length;
|
|
outUpper.textContent = val.toUpperCase();
|
|
outLower.textContent = val.toLowerCase();
|
|
outEncoded.textContent = encodeURIComponent(val);
|
|
|
|
// URL Decoded
|
|
try {
|
|
outDecoded.textContent = decodeURIComponent(val);
|
|
outDecoded.classList.remove('error-text');
|
|
urlDecodedCard.classList.remove('error');
|
|
} catch (e) {
|
|
outDecoded.textContent = "Error: Invalid URL encoding sequence";
|
|
outDecoded.classList.add('error-text');
|
|
urlDecodedCard.classList.add('error');
|
|
}
|
|
|
|
// Base64 Encoded
|
|
outB64Enc.textContent = utf8ToBase64(val);
|
|
|
|
// Base64 Decoded (Hidden unless input is valid Base64)
|
|
const trimmedVal = val.trim();
|
|
// Regex validates Base64 formatting before attempting decoding
|
|
const isB64Format = /^[A-Za-z0-9+/=]+$/.test(trimmedVal) && (trimmedVal.length % 4 === 0);
|
|
|
|
if (isB64Format) {
|
|
try {
|
|
const decoded = base64ToUtf8(trimmedVal);
|
|
outB64Dec.textContent = decoded;
|
|
b64DecCard.classList.remove('hidden');
|
|
} catch (e) {
|
|
b64DecCard.classList.add('hidden');
|
|
}
|
|
} else {
|
|
b64DecCard.classList.add('hidden');
|
|
}
|
|
|
|
// Calculate Cryptographic Hashes asynchronously
|
|
try {
|
|
outSha1.textContent = await computeHash('SHA-1', val);
|
|
outSha256.textContent = await computeHash('SHA-256', val);
|
|
outSha512.textContent = await computeHash('SHA-512', val);
|
|
} catch (e) {
|
|
outSha1.textContent = "Error computing hash";
|
|
outSha256.textContent = "Error computing hash";
|
|
outSha512.textContent = "Error computing hash";
|
|
}
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html> |