Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit 654cbfb

Browse files
authored
Update index.html
Signed-off-by: Blake Arnold <[email protected]>
1 parent 4199fa5 commit 654cbfb

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

index.html

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,13 @@
293293
<button type="button" id="downloadAllBtn" style="display:none" onclick="downloadAllFiles()">Download All Files</button>
294294
</div>
295295
<div id="tab2" class="tab-content">
296-
Ciphertext:
297-
<textarea id="ciphertext"></textarea>
298-
<button type="button" onclick="decrypt()">Decrypt</button>
299-
</div>
296+
Ciphertext:
297+
<textarea id="ciphertext"></textarea>
298+
<button type="button" onclick="decrypt()">Decrypt</button>
299+
<button type="button" id="downloadCipherBtn">Download .ciphertext</button>
300+
<input type="file" id="uploadCipherInput" style="display:none" accept=".ciphertext">
301+
<button type="button" onclick="document.getElementById('uploadCipherInput').click()">Upload .ciphertext</button>
302+
</div>
300303
</body>
301304
<script>
302305
function strToBuf(str) {
@@ -623,6 +626,47 @@
623626
document.querySelectorAll('#tabs .tab')[1].classList.add('active');
624627
}
625628
}
629+
document.getElementById('downloadCipherBtn').addEventListener('click', function() {
630+
const ciphertext = document.getElementById('ciphertext').value.trim();
631+
const num = document.getElementById('num').value.trim();
632+
if (!ciphertext || !num) {
633+
alert("Ciphertext and message number are required.");
634+
return;
635+
}
636+
const data = JSON.stringify({ciphertext: ciphertext, number: num});
637+
const blob = new Blob([data], {type: 'application/json'});
638+
const a = document.createElement('a');
639+
a.href = URL.createObjectURL(blob);
640+
a.download = "ciphertext.ciphertext";
641+
document.body.appendChild(a);
642+
a.click();
643+
setTimeout(() => {
644+
document.body.removeChild(a);
645+
URL.revokeObjectURL(a.href);
646+
}, 100);
647+
});
648+
649+
document.getElementById('uploadCipherInput').addEventListener('change', function(e) {
650+
const file = e.target.files[0];
651+
if (!file) return;
652+
const reader = new FileReader();
653+
reader.onload = function(event) {
654+
try {
655+
const obj = JSON.parse(event.target.result);
656+
if (typeof obj.ciphertext === "string" && typeof obj.number !== "undefined") {
657+
document.getElementById('ciphertext').value = obj.ciphertext;
658+
document.getElementById('num').value = obj.number;
659+
alert("Ciphertext and message number loaded. Enter your key and click Decrypt.");
660+
} else {
661+
alert("Invalid ciphertext file.");
662+
}
663+
} catch {
664+
alert("Could not read .ciphertext file.");
665+
}
666+
e.target.value = ""; // reset input so same file can be chosen again if needed
667+
};
668+
reader.readAsText(file);
669+
});
626670
showTabContent('tab1');
627671
updateFileLists();
628672
updateDownloadAllBtn();

0 commit comments

Comments
 (0)