C# 位对位异或 &文件输入/输出
好的,我有一个 35 MB 的文件,它是通过位对位异或加密的(我相信是按位异或),我想知道一种解密它的好方法,然后使用 C# 上的文件 I/O 再次加密它。
这是 Enc/Dec 算法:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不是按位异或 - 它实际上是按位替换密码。您知道这只是最宽松意义上的“加密”,对吗?
基本上,您需要两个步骤:
BinaryReader
和BinaryWriter
来实现此目的。(显然,您可以通过缓冲进行优化,但这就是一般要点。)
您可能会发现使用
uint
而不是int
来避免担心符号位是最简单的。像这样的事情:您可以使用一个用于加密的表和一个用于解密的表来使这个表驱动,但我不确定我是否会打扰。
请注意,如果您实际上使用它来存储敏感信息,则应尽快开始使用真实加密。
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:
BinaryReader
andBinaryWriter
for this.(Obviously you can optimize with buffering, but that's the general gist.)
You may find it's easiest to work with
uint
instead ofint
to 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.
首先,您必须执行一个函数来获取单个位,然后执行一个函数将其保存在您想要的任何位置:
然后您必须手动执行每个转换,例如(如果我正确理解您的算法):
First you have to do a function to get a single bit and a function to save it wherever you want:
Then you have to do each conversion manually, something like (if I understood your algorithm correctly):
这不是XOR。如果是这样,您只需再次对具有相同值的数据进行异或即可解密它。
您所描述的是某种位加扰加密。
正如其他人所说,这不是安全加密。它使用一种通常称为“通过模糊实现安全性”的方法。
That isn't XOR. If it was you'd simply XOR the data with the same value again to decrypt it.
What you are describing is some kind of bit scrambling encryption.
As others have said, this is not secure encryption. It uses a method commonly known as "security through obscurity."