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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="vi">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>CVNSS4.0 ⇄ Bila Hex/Nhị phân | Chưa hỗ trợ chuỗi dài</title>
|
| 6 |
+
<style>
|
| 7 |
+
body { background: #1e2232; font-family: 'Fira Mono', monospace; margin: 0; }
|
| 8 |
+
.container { max-width: 760px; margin: 44px auto; background: #181f29; border-radius: 16px;
|
| 9 |
+
box-shadow: 0 3px 18px #000c; padding: 32px 24px 24px 24px;}
|
| 10 |
+
h2 { color: #e0e7ef; font-weight: 500; margin-bottom: 8px;}
|
| 11 |
+
label { font-weight: bold; color: #38bdf8; margin-top: 12px; display: block;}
|
| 12 |
+
textarea { width: 100%; font-size: 1em; background: #1e293b; color: #f1f5f9;
|
| 13 |
+
border-radius: 7px; padding: 12px; border: 1px solid #334155;
|
| 14 |
+
margin-bottom: 14px; min-height: 48px; resize: vertical;}
|
| 15 |
+
button { background: #38bdf8; color: #020617; border: none; border-radius: 8px;
|
| 16 |
+
padding: 11px 20px; font-size: 1em; font-family: inherit; font-weight: 600;
|
| 17 |
+
margin: 7px 13px 7px 0; box-shadow: 0 1px 5px #0891b2aa; transition: 0.12s;}
|
| 18 |
+
button:hover { background: #0ea5e9; color: #fff;}
|
| 19 |
+
.outblock { background: #222b38; border-radius: 8px; margin-top: 12px; margin-bottom: 10px; }
|
| 20 |
+
.outlabel { color: #6ee7b7; font-size: 0.99em; padding: 8px 0 2px 2px; }
|
| 21 |
+
.output { color: #e5e5e5; background: none; padding: 8px 8px 4px 8px; font-size: 1.08em;
|
| 22 |
+
word-break: break-all; font-family: 'Fira Mono', monospace; min-height: 16px;}
|
| 23 |
+
.error { color: #f87171; font-weight: bold; padding: 7px 0 0 0;}
|
| 24 |
+
.note { color: #a5b4fc; font-size: 0.97em; margin-top: 12px;}
|
| 25 |
+
.byline { text-align: right; margin-top: 26px; color: #64748b; font-size: 0.97em;}
|
| 26 |
+
@media (max-width: 800px) { .container {padding: 10px; max-width: 99vw;} }
|
| 27 |
+
::selection { background: #38bdf888; }
|
| 28 |
+
</style>
|
| 29 |
+
</head>
|
| 30 |
+
<body>
|
| 31 |
+
<div class="container">
|
| 32 |
+
<h2>CVNSS4.0 ⇄ Bila Hex/Nhị phân<br> Hiện chỉ hỗ trợ khoảng 30 ký tự để test</h2>
|
| 33 |
+
|
| 34 |
+
<label for="ascii">CVNSS4.0:</label>
|
| 35 |
+
<textarea id="ascii" placeholder="Nhập chữ cái, số, dấu cách... Chuỗi dài cỡ 50 ký tự đều được!"></textarea>
|
| 36 |
+
<button onclick="asciiToCBOR()">CVNSS4.0 → Bila</button>
|
| 37 |
+
<button onclick="clearAll()">Xoá</button>
|
| 38 |
+
<div class="error" id="err_ascii"></div>
|
| 39 |
+
|
| 40 |
+
<div class="outblock">
|
| 41 |
+
<div class="outlabel">Bila Hex:</div>
|
| 42 |
+
<div class="output" id="cborhex"></div>
|
| 43 |
+
<div class="outlabel">Bila Nhị phân:</div>
|
| 44 |
+
<div class="output" id="cborbin"></div>
|
| 45 |
+
</div>
|
| 46 |
+
|
| 47 |
+
<label for="cborhex_in">Bila Hex:</label>
|
| 48 |
+
<textarea id="cborhex_in" placeholder="Nhập mã Hex hợp lệ (header 78xx, 79xxxx, ... không giới hạn độ dài)"></textarea>
|
| 49 |
+
<button onclick="cborHexToAscii()">Bila Hex → CVNSS4.0</button>
|
| 50 |
+
<div class="error" id="err_hex"></div>
|
| 51 |
+
|
| 52 |
+
<label for="cborbin_in">Bila Nhị phân:</label>
|
| 53 |
+
<textarea id="cborbin_in" placeholder="Nhập mã Nhị phân hợp lệ"></textarea>
|
| 54 |
+
<button onclick="cborBinToAscii()">Bila Nhị phân → CVNSS4.0</button>
|
| 55 |
+
<div class="error" id="err_bin"></div>
|
| 56 |
+
|
| 57 |
+
<div class="outblock">
|
| 58 |
+
<div class="outlabel">Kết quả:</div>
|
| 59 |
+
<div class="output" id="ascii_out"></div>
|
| 60 |
+
</div>
|
| 61 |
+
|
| 62 |
+
<div class="note">
|
| 63 |
+
• Nhập/dán tối đa 30-40 ký tự.<br>
|
| 64 |
+
• Tự động loại ký tự không hợp lệ (chỉ giữ A–Z, a–z, 0–9, dấu cách).<br>
|
| 65 |
+
• Mã Hex dài sẽ tự động dùng header 78xx, 79xxxx theo chuẩn RFC7049.<br>
|
| 66 |
+
• Kết quả chưa tương thích sẽ báo lỗi, lấy ký tự CVNSS4.0 (<a href="https://chuvnsongsong.com/" target="_blank" style="color:#38bdf8">Chữ VN Song Song 4.0</a>).
|
| 67 |
+
</div>
|
| 68 |
+
<div class="byline">© Long Ngo, 2025 – Bản demo đang thử nghiệm</div>
|
| 69 |
+
</div>
|
| 70 |
+
<script>
|
| 71 |
+
// Chặn realtime ký tự lạ khi gõ/dán vào textarea (giữ input sạch)
|
| 72 |
+
document.getElementById('ascii').addEventListener('input', function() {
|
| 73 |
+
let clean = this.value.replace(/[^A-Za-z0-9 ]+/g, '');
|
| 74 |
+
if(this.value !== clean) {
|
| 75 |
+
this.value = clean;
|
| 76 |
+
document.getElementById('err_ascii').textContent = '❌ Đã tự động loại bỏ ký tự không hợp lệ!';
|
| 77 |
+
} else {
|
| 78 |
+
document.getElementById('err_ascii').textContent = '';
|
| 79 |
+
}
|
| 80 |
+
});
|
| 81 |
+
|
| 82 |
+
function cleanASCII(s) {
|
| 83 |
+
return s.replace(/[\r\n\t\u200B-\u200D\uFEFF]/g, "");
|
| 84 |
+
}
|
| 85 |
+
function checkValidASCII(s) {
|
| 86 |
+
return /^[A-Za-z0-9 ]+$/.test(s);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
// Hỗ trợ CBOR chuẩn mọi độ dài: <24, <256, <65536 ký tự
|
| 90 |
+
function asciiToCBOR() {
|
| 91 |
+
let t = document.getElementById('ascii').value;
|
| 92 |
+
document.getElementById('err_ascii').textContent = "";
|
| 93 |
+
if (!t) return showCBOR('', '');
|
| 94 |
+
let tclean = cleanASCII(t);
|
| 95 |
+
if (!checkValidASCII(tclean)) {
|
| 96 |
+
let wrong = tclean.replace(/[A-Za-z0-9 ]/g, "");
|
| 97 |
+
document.getElementById('err_ascii').textContent =
|
| 98 |
+
'❌ Chỉ cho phép A–Z, a–z, 0–9, dấu cách! Ký tự lỗi: [' + wrong.split("").join(" ") + ']';
|
| 99 |
+
showCBOR('', '');
|
| 100 |
+
return;
|
| 101 |
+
}
|
| 102 |
+
let encoder = new TextEncoder();
|
| 103 |
+
let bytes = encoder.encode(tclean);
|
| 104 |
+
let hex = "", b = "";
|
| 105 |
+
if (bytes.length < 24) {
|
| 106 |
+
hex = (0x60 + bytes.length).toString(16);
|
| 107 |
+
} else if (bytes.length < 256) {
|
| 108 |
+
hex = "78" + bytes.length.toString(16).padStart(2, "0");
|
| 109 |
+
} else if (bytes.length < 65536) {
|
| 110 |
+
hex = "79" + bytes.length.toString(16).padStart(4, "0");
|
| 111 |
+
} else {
|
| 112 |
+
document.getElementById('err_ascii').textContent = '❌ Chuỗi quá dài (tối đa 65.535 ký tự)!';
|
| 113 |
+
showCBOR('', '');
|
| 114 |
+
return;
|
| 115 |
+
}
|
| 116 |
+
hex += Array.from(bytes).map(x => x.toString(16).padStart(2, "0")).join('');
|
| 117 |
+
b = hex.match(/.{1,2}/g).map(x => parseInt(x, 16).toString(2).padStart(8, '0')).join('');
|
| 118 |
+
showCBOR(hex, b);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
function cborHexToAscii() {
|
| 122 |
+
let hex = document.getElementById('cborhex_in').value
|
| 123 |
+
.replace(/[^0-9a-fA-F]/g, '')
|
| 124 |
+
.toLowerCase();
|
| 125 |
+
document.getElementById('err_hex').textContent = "";
|
| 126 |
+
if (!hex) return showAscii('');
|
| 127 |
+
if (hex.length % 2 !== 0) {
|
| 128 |
+
document.getElementById('err_hex').textContent = '❌ Hex phải có số ký tự chẵn!';
|
| 129 |
+
showAscii('');
|
| 130 |
+
return;
|
| 131 |
+
}
|
| 132 |
+
if (!/^[0-9a-f]+$/.test(hex)) {
|
| 133 |
+
document.getElementById('err_hex').textContent = '❌ Hex không hợp lệ!';
|
| 134 |
+
showAscii('');
|
| 135 |
+
return;
|
| 136 |
+
}
|
| 137 |
+
try {
|
| 138 |
+
let idx=0, l=0, fb=parseInt(hex.substr(idx,2),16); idx+=2;
|
| 139 |
+
if ((fb&0xe0)===0x60) l=fb&0x1f;
|
| 140 |
+
else if(fb===0x78) { l=parseInt(hex.substr(idx,2),16); idx+=2; }
|
| 141 |
+
else if(fb===0x79) { l=parseInt(hex.substr(idx,4),16); idx+=4; }
|
| 142 |
+
else { document.getElementById('err_hex').textContent = '❌ Không đúng mã string'; showAscii(''); return; }
|
| 143 |
+
let bh = hex.substr(idx, l*2);
|
| 144 |
+
if (bh.length<l*2) {
|
| 145 |
+
document.getElementById('err_hex').textContent = '❌ Thiếu bytes, cần ' + (l*2) + ' ký tự hex, chỉ có ' + bh.length;
|
| 146 |
+
showAscii('');
|
| 147 |
+
return;
|
| 148 |
+
}
|
| 149 |
+
let bs=[];
|
| 150 |
+
for(let i=0;i<bh.length;i+=2) bs.push(parseInt(bh.substr(i,2),16));
|
| 151 |
+
let s;
|
| 152 |
+
try {
|
| 153 |
+
s = new TextDecoder().decode(new Uint8Array(bs));
|
| 154 |
+
} catch (e) {
|
| 155 |
+
document.getElementById('err_hex').textContent = '❌ Không thể giải mã UTF-8: ' + e.message;
|
| 156 |
+
showAscii('');
|
| 157 |
+
return;
|
| 158 |
+
}
|
| 159 |
+
let clean = cleanASCII(s);
|
| 160 |
+
if (!checkValidASCII(clean)) {
|
| 161 |
+
let wrong = clean.replace(/[A-Za-z0-9 ]/g, "");
|
| 162 |
+
document.getElementById('err_hex').textContent =
|
| 163 |
+
'❌ Dữ liệu nhập không hợp lệ (chỉ cho A–Z, a–z, 0–9, dấu cách)! Ký tự lỗi: [' +
|
| 164 |
+
wrong.split("").join(" ") + ']';
|
| 165 |
+
showAscii('');
|
| 166 |
+
return;
|
| 167 |
+
}
|
| 168 |
+
showAscii(clean);
|
| 169 |
+
} catch (err) {
|
| 170 |
+
document.getElementById('err_hex').textContent = '❌ Lỗi giải mã: ' + err.message;
|
| 171 |
+
showAscii('');
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
function cborBinToAscii() {
|
| 176 |
+
let bin = document.getElementById('cborbin_in').value.trim().replace(/\s+/g,'');
|
| 177 |
+
document.getElementById('err_bin').textContent = "";
|
| 178 |
+
if (!bin) return showAscii('');
|
| 179 |
+
if (!/^[01]+$/.test(bin)) { document.getElementById('err_bin').textContent = '❌ Nhị phân không hợp lệ!'; showAscii(''); return; }
|
| 180 |
+
if (bin.length%8!==0) { document.getElementById('err_bin').textContent = '❌ Chuỗi phải là bội số 8!'; showAscii(''); return; }
|
| 181 |
+
try {
|
| 182 |
+
let idx=0, l=0, fb=parseInt(bin.substr(idx,8),2); idx+=8;
|
| 183 |
+
if ((fb&0xe0)===0x60) l=fb&0x1f;
|
| 184 |
+
else if(fb===0x78) { l=parseInt(bin.substr(idx,8),2); idx+=8; }
|
| 185 |
+
else if(fb===0x79) { l=parseInt(bin.substr(idx,16),2); idx+=16; }
|
| 186 |
+
else { document.getElementById('err_bin').textContent = '❌ Không đúng CBOR string'; showAscii(''); return; }
|
| 187 |
+
let bs=[];
|
| 188 |
+
for(let i=0;i<l;i++) {
|
| 189 |
+
if(idx+8>bin.length) { document.getElementById('err_bin').textContent = '❌ Thiếu bytes'; showAscii(''); return; }
|
| 190 |
+
bs.push(parseInt(bin.substr(idx,8),2)); idx+=8;
|
| 191 |
+
}
|
| 192 |
+
let s;
|
| 193 |
+
try {
|
| 194 |
+
s = new TextDecoder().decode(new Uint8Array(bs));
|
| 195 |
+
} catch (e) {
|
| 196 |
+
document.getElementById('err_bin').textContent = '❌ Không thể giải mã UTF-8: ' + e.message;
|
| 197 |
+
showAscii('');
|
| 198 |
+
return;
|
| 199 |
+
}
|
| 200 |
+
let clean = cleanASCII(s);
|
| 201 |
+
if (!checkValidASCII(clean)) {
|
| 202 |
+
let wrong = clean.replace(/[A-Za-z0-9 ]/g, "");
|
| 203 |
+
document.getElementById('err_bin').textContent =
|
| 204 |
+
'❌ Dữ liệu nhập không hợp lệ (chỉ cho A–Z, a–z, 0–9, dấu cách)! Ký tự lỗi: [' +
|
| 205 |
+
wrong.split("").join(" ") + ']';
|
| 206 |
+
showAscii('');
|
| 207 |
+
return;
|
| 208 |
+
}
|
| 209 |
+
showAscii(clean);
|
| 210 |
+
} catch (err) {
|
| 211 |
+
document.getElementById('err_bin').textContent = '❌ Lỗi giải mã: ' + err.message;
|
| 212 |
+
showAscii('');
|
| 213 |
+
}
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
function showCBOR(hex, bin) {
|
| 217 |
+
document.getElementById('cborhex').textContent = hex;
|
| 218 |
+
document.getElementById('cborbin').textContent = bin;
|
| 219 |
+
document.getElementById('ascii_out').textContent = "";
|
| 220 |
+
}
|
| 221 |
+
function showAscii(ascii) {
|
| 222 |
+
document.getElementById('ascii_out').textContent = ascii;
|
| 223 |
+
}
|
| 224 |
+
function clearAll() {
|
| 225 |
+
document.getElementById('ascii').value = '';
|
| 226 |
+
document.getElementById('cborhex_in').value = '';
|
| 227 |
+
document.getElementById('cborbin_in').value = '';
|
| 228 |
+
document.getElementById('err_ascii').textContent = '';
|
| 229 |
+
document.getElementById('err_hex').textContent = '';
|
| 230 |
+
document.getElementById('err_bin').textContent = '';
|
| 231 |
+
showCBOR('', '');
|
| 232 |
+
showAscii('');
|
| 233 |
+
}
|
| 234 |
+
</script>
|
| 235 |
+
</body>
|
| 236 |
</html>
|