|
293 | 293 | <button type="button" id="downloadAllBtn" style="display:none" onclick="downloadAllFiles()">Download All Files</button> |
294 | 294 | </div> |
295 | 295 | <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> |
300 | 303 | </body> |
301 | 304 | <script> |
302 | 305 | function strToBuf(str) { |
|
623 | 626 | document.querySelectorAll('#tabs .tab')[1].classList.add('active'); |
624 | 627 | } |
625 | 628 | } |
| 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 | +}); |
626 | 670 | showTabContent('tab1'); |
627 | 671 | updateFileLists(); |
628 | 672 | updateDownloadAllBtn(); |
|
0 commit comments