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. PBYTE restore_original(PBYTE high_ent_payload) { constexpr int payload_size = (payload_size_after_entropy_reduction + 1) / 2; // re-calculate the original payload size BYTE low_entropy_payload_holder[payload_size_after_entropy_reduction] = {0}; // create a new array to hold the bytes to be processed memcpy_s(low_entropy_payload_holder, sizeof low_entropy_payload_holder, high _ent_payload, payload_size_after_entropy_reduction); // move the array to be pro cessed to the newly created array // Create an empty array which will contain the restored data static BYTE restored_payload[payload_size] = {0}; int offset_of_hi_entropy_payload = 0; int offset_of_original_payload = 0; // Because high and low entropy chunks are of the same size, then simply cop y 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++) { restored_payload[offset_of_original_payload] = low_entropy_payload_h older[offset_of_hi_entropy_payload]; offset_of_hi_entropy_payload++; offset_of_original_payload++; } for (size_t k = 0; k < chunk_size; k++) { offset_of_hi_entropy_payload++; } } // Copy the remaining bytes if (remaining_bytes) { for (size_t i = 0; i < sizeof remaining_bytes; i++) { restored_payload[offset_of_original_payload++] = high_ent_payload[of fset_of_hi_entropy_payload++]; } } return restored_payload; } 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.