Implementation of XOR encryption algorithm for Android data encryption
In recent days, the company temporarily asked the company to implement the Android im instant messaging protocol, and roughly looked at the agreement they set. Because they had not participated before, it is said that due to server performance constraints, only non plaintext transmission was reached. I don't know the specific reason, but the encryption method used here is XOR encryption. This encryption method has been used in Android encryption Notepad before. Today, we have finished the connection of client heartbeat maintenance and packet analysis. Let's summarize this encryption method.
What is XOR encryption?
In the XOR operation, if a character (or numerical value) x is XORed with a numerical value m to obtain y, then the XOR operation with y and M can be restored to X. therefore, the function of data encryption and decryption can be realized by applying this principle.
XOR usage scenario?
Interchange of two variables (without the aid of the third variable)
Simple encryption and decryption of data
XOR encryption and decryption implementation?
1. Fixed key
Test encryption and decryption
2. The key is not fixed
Encryption implementation
Decryption implementation
test
Summary:
Bit operation can realize many advanced and efficient operations. For example, encryption, the n-th power in multiplication is to shift n bits to the right, which is fast. Im binary data packet adopts XOR algorithm. Firstly, it can realize encryption. Secondly, the XOR encryption algorithm will not change the length of binary data, which is of great benefit to binary data packet. Therefore, this summary is made.
The above is all about the implementation method of XOR encryption algorithm of Android data encryption brought by Xiaobian. I hope you can support more programming tips~