From ab52c481ec00796b5e695c6c6b3a194ac4ad6117 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Mon, 29 Jul 2024 20:33:23 -0400 Subject: [PATCH] update --- src/reassemble.html | 4 ++-- src/splitter.html | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/reassemble.html b/src/reassemble.html index 14507b6..21abe49 100644 --- a/src/reassemble.html +++ b/src/reassemble.html @@ -119,7 +119,7 @@ const firstMessage = document.getElementById('firstMessage').value.trim(); const lines = firstMessage.split('\n'); - if (lines.length < 2) { + if (lines.length < 3) { alert('Invalid format for the first message.'); return; } @@ -156,7 +156,7 @@ const firstMessage = document.getElementById('firstMessage').value.trim(); const lines = firstMessage.split('\n'); - if (lines.length < 2) { + if (lines.length < 3) { alert('Invalid format for the first message.'); return; } diff --git a/src/splitter.html b/src/splitter.html index 2bb9e31..63d5110 100644 --- a/src/splitter.html +++ b/src/splitter.html @@ -110,22 +110,24 @@ const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join(''); - // Prepare the prefix for the first chunk - const firstChunkPrefix = `Hash: ${hashHex}\nMessage 1/`; - const firstChunkContentSize = maxChunkSize - firstChunkPrefix.length - (String(text.length).length + 2); + // Calculate the total number of chunks + const totalChunks = Math.ceil(text.length / (maxChunkSize - 20)) + 1; // Considering extra space for prefixes + + // Prepare the first chunk with hash and sequence + const firstChunkPrefix = `Hash: ${hashHex}\nMessage 1/${totalChunks}\n\n`; + const firstChunkContentSize = maxChunkSize - firstChunkPrefix.length; const firstChunk = firstChunkPrefix + text.substring(0, firstChunkContentSize); - + // Add the first chunk to the list chunks.push(firstChunk); // Split the remaining text into chunks - for (let i = firstChunkContentSize; i < text.length; i += maxChunkSize) { - let chunk = text.substring(i, i + maxChunkSize); - let chunkNumber = Math.floor(i / maxChunkSize) + 2; // Start from the second chunk - let totalChunks = Math.ceil(text.length / maxChunkSize) + 1; - let prefix = `Message ${chunkNumber}/${totalChunks}`; + for (let i = firstChunkContentSize; i < text.length; i += maxChunkSize - 20) { + let chunk = text.substring(i, i + (maxChunkSize - 20)); + let chunkNumber = Math.floor(i / (maxChunkSize - 20)) + 2; // Start from the second chunk + let prefix = `Message ${chunkNumber}/${totalChunks}\n\n`; - chunk = `${prefix}\n\n${chunk}`; + chunk = `${prefix}${chunk}`; chunks.push(chunk); }