[C#] Split Byte[] Into Chunks 06-16-2014, 09:52 PM
#1
I was developing a Crypter some time ago and I needed to split the payload in-to multiple byte[].
Nothing advanced, but maybe someone needs this.
What it does?
If you have a Byte[] with Length of 8 and you specify Size to 6
You will then have Two Byte[], one with Size of 6 and the other of 2.
Code:
static List<Byte[]> SplitIntoChunks(Byte[] arr_bInput, Int32 iSize)
{
List<Byte[]> lstChunks = new List<Byte[]>();
List<Byte> lstChunk = new List<Byte>();
for(int i = 0; i < arr_bInput.Length; i++)
{
lstChunk.Add(arr_bInput[i]);
if (i == iSize - 1 || i == arr_bInput.Length - 1 )
{
lstChunks.Add(lstChunk.ToArray());
lstChunk.Clear();
}
}
return lstChunks;
}Nothing advanced, but maybe someone needs this.
What it does?
If you have a Byte[] with Length of 8 and you specify Size to 6
You will then have Two Byte[], one with Size of 6 and the other of 2.


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)