# Entropy code

zeynepaydogan zeynepaydogan at proton.me
Thu May 5 19:08:51 PDT 2022

```Notice, as an unrelated side note, that in c++ you can't pass full arrays to functions as you would in managed languages, you have to pass a pointer to the first byte of an array to be processed and the return
a pointer to the first byte of the resulting processed array. The function copies the chunks of high entropy code to a new array and inserts a pattern of ascending bytes starting by a initial random byte.
Not all bytes can be random because the entropy would not be reduced, so only the first one is. There rest will follow a pattern and here of course you can select many different patterns. For this example I
used a simple incremental pattern.

Final task will restore the original byte array by eliminating the inserted low entropy chunks of code.

{
BYTE low_entropy_payload_holder[payload_size_after_entropy_reduction] = {0}; // create a new array to hold the bytes to be processed

// Create an empty array which will contain the restored data

// Because high and low entropy chunks are of the same size, then simply copy the high entropy ones to the restored array and skip the low entropy ones
for (size_t i = 0; i < number_of_chunks; i++)
{
for (size_t j = 0; j < chunk_size; j++)
{
}
for (size_t k = 0; k < chunk_size; k++)
{
}
}
// Copy the remaining bytes
if (remaining_bytes)
{
for (size_t i = 0; i < sizeof remaining_bytes; i++)
{
}
}
}

So lets explain this graphically. Suppose a byte belonging to a high entropy chunk is represented by the letter "H" and a low entropy byte belonging to a low entropy chunk is represented by the letter "L", and the
remaining never modified bytes are represented by the letter "R"

The original high entropy array is something like this: HHHHHHHHHHHHHHHHHRRR
The processed low entropy array is something like this: HHHHLLLLHHHHLLLLHHHHLLLLHHHHRRR

So to restore the original high entropy array from the low entropy processed array we simply eliminate the low entropy "L" bytes and we finally append the remaining "R" bytes.
The restored high entropy array is something like this after low entropy chunks elimination: HHHHHHHHHHHHHHHHHRRR

Finally we can explain the main function that will use the previous two functions to perform all the jobs, and to make sure that all of this works, we will calculate the Shannon entropy at each step to corroborate
entropy is high at the beginning, then reduced and finally its increased once more.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/html
Size: 4203 bytes
Desc: not available
URL: <https://lists.cpunks.org/pipermail/cypherpunks/attachments/20220506/ef6af911/attachment.txt>
```