Hi everyone,
I did write a small vb.net program to encrypt and decrypt DESX.
Its actually nearly the same as DES but with an additional input and output XOR with two extra keys.
wo8Bl.png
So when I decrypt files it easy really fast taking around 10sec for 100mb.
This is because I can decrypt the complete file first without needing to go from one block to the next.
But when I encrypt files I need to chain 8 byte sized chunks in serial.
My vb.net code looks like this:
Code:
'DES-X Start
Dim xor_in_array As Byte() = XORarrayValues(input_whitener_array, ByteToEncrypt)
Dim ciphertext As Byte() = New Byte(ByteToEncrypt.Length - 1) {}
Dim ms As New MemoryStream
Dim cs As New CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write)
Dim cut_bytes() As Byte = New Byte(8 - 1) {}
For i = 0 To (xor_in_array.Length / 8) - 1
Array.Copy(xor_in_array, CInt(i) * 8, cut_bytes, 0, 8)
If i = 0 Then
Dim xor_iv = XORarrayValues(cut_bytes, Var.iv)
ms.Position = 0
cs.Write(xor_iv, 0, xor_iv.Length)
Dim des_xor_iv = ms.ToArray()
Dim xor_out = XORarrayValues(Var.output_whitener, des_xor_iv)
Array.Copy(xor_out, 0, ciphertext, CInt(i) * 8, 8)
Else
Dim ciphertext_used() As Byte = New Byte(8 - 1) {}
Array.Copy(ciphertext, CInt(i - 1) * 8, ciphertext_used, 0, 8)
Dim xor_ciphertext_used = XORarrayValues(cut_bytes, ciphertext_used)
ms.Position = 0
cs.Write(xor_ciphertext_used, 0, xor_ciphertext_used.Length)
Dim des_xor_out = ms.ToArray()
Dim xor_out = XORarrayValues(Var.output_whitener, des_xor_out)
For j = 0 To xor_out.Length - 1
ciphertext(i * 8 + j) = xor_out(j)
Next
'Array.Copy(xor_out, 0, ciphertext, CInt(i) * 8, 8)
'ciphertext = ciphertext.Concat(xor_out).ToArray()
End If
So I tried different approaches in appending the ciphertext at the end to a bte array so i can write it to file afterwards.
It does not change in speed if I use array.copy / concat or for loop copy.
I also tried with creating 4-8 parallel threads. While this reduces the time needed for encryption, it is still slow for very big files.
How can I increase speed for the encryption algorithm? Hope someone has a solution.
Thx.
-e