首页
社区
课程
招聘
[求助]C# XOR Encryption
发表于: 2010-8-26 04:56 1201

[求助]C# XOR Encryption

2010-8-26 04:56
1201
C# XOR Encryption
String Encryption

C# xor encryption is a primitive way to encrypt string data. It should never be used for secure encryption. However it is a simple way to hide meaningful text from plain sight.

Xor encryption does offer the use of a number key, making decryption only possible with said key.
Xor Operator

The basis of the encryption is the xor operator. In a nutshell, the xor operator works this way with numbers:

value1 xor value2 = value3
value3 xor value2 = value1

As you can probably tell, xor encryption will work based on value2 which in this case will be your number key.
Xor Encryption

The algorithm is simple, go through each character in the string, convert it to its integer ASCII value, xor the value with the key, and convert the new value back into a string.

To convert a character to an int, use:

Convert.ToInt32([char here]);

To convert an int to a char, use:

char.ConvertFromUtf32([int here]);

Since the xor operator is basically flipping values, you do not need a separate encryption and decryption function. Only one funciton is needed to flip the character values. Xor encryption is simple, but is a good introduction to string encryption.

[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

上传的附件:
收藏
免费 0
支持
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回
//