How to make an Encode function based on this Decode function? I got the source cod开发者_如何转开发e for the Decode function on the internet but I need the Encode function.
All my attempts to make it failed and the original coder isn't available at the moment.
The (original) code:
byte Decode(byte EncodedByte)
{
EncodedByte ^= (byte)194;
EncodedByte = (byte)((EncodedByte << 4) | (EncodedByte >> 4));
return EncodedByte;
}
Just some quick back of the napkin coding the answer should be
byte Encode(byte DecodedByte)
{
DecodedByte = (byte)((DecodedByte << 4) | (DecodedByte >> 4));
DecodedByte ^= (byte)194;
return DecodedByte;
}
Also I agree with Alex this is a trivial Encryption method. Anyone who knows the algorithm can trivially decrypt your message. I would not rely on it for any sensitive information and if this is code for public use some countries have laws that data must have some form of encryption. If I was a judge for the person suing you for a data breach I would call this more of a obfuscation technique then a encryption technique.
byte Encode(byte EncodedByte)
{
EncodedByte = (byte)((EncodedByte << 4) | (EncodedByte >> 4));
EncodedByte ^= (byte)194;
return EncodedByte;
}
Why do not you use normal encryption/decryption functions of c#?
Encrypt and decrypt a string
精彩评论