XOR'ing two memoryblocks

I have a method that takes two memoryblocks, reads uint64values at a time (within a FOR/NEXT loop), XORs them, and writes them to another memoryblock for output. The issue is, doing this is extremely slow (about 14 seconds for a 1MB file) on my system. Anybody have any recommendations or suggestions that could help is speeding this up?

Sample (rough draft, as I’m typing this in directly w/o my code in front of me… but basically doing it like this [minus the clean-up for the last few bytes]):

for int_position = 0 to fld_file.length - 1 step 8
   mem_cipher.uint64value(int_position) = bitwise.bitxor(mem_pad.uint64value(int_position), mem_plaintext.uint64value(int_position))
next int_position

I wrote an entire class around bitwise operations, if you want to see if that’s faster. You could read in your 1 MB at a time if you wanted. Let me know.

Sorry, I should clarify. My class is called BitBloxk and it’s designed to allow access to bits the way a MemoryBlock allows access to bytes, and includes bitwise operations of one BitBlock against another BitBlock.


Absolutely… that would be much appreciated!

Get it from:


You also need my M_String module, available at my web site.

The Xor operator is faster than Bitwise.BitXor, maybe up to 4x.

mem_cipher.uint64value(int_position) = _ mem_pad.uint64value(int_position) Xor mem_plaintext.uint64value(int_position)

Thank you!

For best speed don’t recalculate the end position on each iteration unless the end position is likely to change.


Dim fld_filelen As Integer = fld_file.length - 1
for int_position = 0 to fld_filelen step 8

This may not yield much of an improvement with MemoryBlocks, though.