OK, I have a 35 MB file, that is Encrypted with Bit to Bit XOR(Bitwise XOR I believe) and I’d like to know a good way to decrypt it, and then encrypt it again, using File I/O on C#.
Here is the Enc/Dec algorithm:
Encrypt:----------------------Decrypt:
Bit 0 -> Bit 26--------------Bit 0 -> Bit 18
Bit 1 -> Bit 31--------------Bit 1 -> Bit 29
Bit 2 -> Bit 17--------------Bit 2 -> Bit 7
Bit 3 -> Bit 10--------------Bit 3 -> Bit 25
Bit 4 -> Bit 30--------------Bit 4 -> Bit 15
Bit 5 -> Bit 16--------------Bit 5 -> Bit 31
Bit 6 -> Bit 24--------------Bit 6 -> Bit 22
Bit 7 -> Bit 2--------------Bit 7 -> Bit 27
Bit 8 -> Bit 29--------------Bit 8 -> Bit 9
Bit 9 -> Bit 8--------------Bit 9 -> Bit 26
Bit 10 -> Bit 20--------------Bit 10 -> Bit 3
Bit 11 -> Bit 15--------------Bit 11 -> Bit 13
Bit 12 -> Bit 28--------------Bit 12 -> Bit 19
Bit 13 -> Bit 11--------------Bit 13 -> Bit 14
Bit 14 -> Bit 13--------------Bit 14 -> Bit 20
Bit 15 -> Bit 4--------------Bit 15 -> Bit 11
Bit 16 -> Bit 19--------------Bit 16 -> Bit 5
Bit 17 -> Bit 23--------------Bit 17 -> Bit 2
Bit 18 -> Bit 0--------------Bit 18 -> Bit 23
Bit 19 -> Bit 12--------------Bit 19 -> Bit 16
Bit 20 -> Bit 14--------------Bit 20 -> Bit 10
Bit 21 -> Bit 27--------------Bit 21 -> Bit 24
Bit 22 -> Bit 6--------------Bit 22 -> Bit 28
Bit 23 -> Bit 18--------------Bit 23 -> Bit 17
Bit 24 -> Bit 21--------------Bit 24 -> Bit 6
Bit 25 -> Bit 3--------------Bit 25 -> Bit 30
Bit 26 -> Bit 9--------------Bit 26 -> Bit 0
Bit 27 -> Bit 7--------------Bit 27 -> Bit 21
Bit 28 -> Bit 22--------------Bit 28 -> Bit 12
Bit 29 -> Bit 1--------------Bit 29 -> Bit 8
Bit 30 -> Bit 25--------------Bit 30 -> Bit 4
Bit 31 -> Bit 5--------------Bit 31 -> Bit 1
This isn’t a bitwise XOR – it’s effectively a bitwise substitution cypher. You realise it’s only “encryption” in the loosest sense of the word, right?
Basically you’ll need two steps:
BinaryReaderandBinaryWriterfor this.(Obviously you can optimize with buffering, but that’s the general gist.)
You may find it’s easiest to work with
uintinstead ofintto avoid worrying about sign bits. Something like this:You could make this table-driven with a table for encryption and a table for decryption, but I’m not sure I’d bother.
Note that if you’re actually using this to store sensitive information, you should start using real encryption as soon as possible.