feat: add signature encoding, auto-detect base on decode, and show notification

This commit is contained in:
2026-09-12 16:11:24 -07:00
parent f15ae68669
commit c5c4daa300
14 changed files with 76 additions and 24 deletions

41
dash.js
View File

@@ -5,13 +5,27 @@ import * as speck32_64ecb from './speck32_64ecb.js';
const textarea = document.getElementById('textarea');
const encoderDropdown = document.getElementById('encoder');
const cipherDropdown = document.getElementById('cipher');
const signBtn = document.getElementById('sign');
const sigDetect = document.getElementById('sigDetect');
const SIG = {
3: '\u{200D}\u{200B}\u{00AD}\u{180E}',
6: '\u{200D}\u{200B}\u{00AD}\u{2060}',
8: '\u{200D}\u{200B}\u{00AD}\u{FEFF}'
};
document.getElementById('encodeButton').addEventListener('click', ACT);
document.getElementById('decodeButton').addEventListener('click', ACT);
document.getElementById('sign').addEventListener('click', e =>
signBtn.addEventListener('click', e =>
e.target.classList.toggle('on')
);
let fadeTimer;
function ACT(event) {
clearTimeout(fadeTimer);
sigDetect.className = '';
if (textarea.value === '') {
textarea.value = 'The text box is empty.';
return;
@@ -19,14 +33,35 @@ function ACT(event) {
const op = event.target.id === 'encodeButton' ? 'NO' : 'YES';
const cipher = getCipherKey();
const base = encoderDropdown.value.split('-')[1];
let base = encoderDropdown.value.split('-')[1];
let text = textarea.value;
if (op === 'YES') {
const sigBase = Object.keys(SIG).find(b => text.includes(SIG[b]));
if (sigBase) {
if (sigBase !== base) {
sigDetect.textContent = `ZWUS-${sigBase} signature detected`;
sigDetect.className = 'show';
fadeTimer = setTimeout(() =>
sigDetect.className = '', 2000
);
}
base = sigBase;
encoderDropdown.value = 'ZWUS-' + base;
text = text.replace(SIG[base], '');
}
}
const needsKey = cipher !== 'PLAIN';
const kStr = needsKey && prompt('enter password.');
if (needsKey && !kStr) return;
try {
textarea.value = DESCRY[op][cipher](textarea.value, base, kStr);
let val = DESCRY[op][cipher](text, base, kStr);
if (op === 'NO' && signBtn.classList.contains('on'))
val = SIG[base] + val;
textarea.value = val;
} catch (e) {
console.log(e);
}