Detailed XOR (exclusive or) operation encryption

Among the logic operation, in addition to AND and OR, there is a XOR operation, Chinese called "exclusive OR operation." It is defined as: two values are the same, it returns false, true otherwise. That is, XOR can be used to determine whether the two values are different.
Detailed operation XOR encryption
Detailed operation XOR encryption
JavaScript language binary arithmetic, there is a dedicated XOR operator, ^ writing.
Detailed operation XOR encryption
If the two bits of the same binary, returns 0, indicating false; 1 otherwise, it indicates true.

XOR application
XOR operation has a wonderful feature: If a value do it twice XOR, will return the value itself.
Detailed operation XOR encryption
In the above code, the original value is 1010, then randomly selecting one value (in the example is 1111), the XOR done twice, and finally will always get the original value 1010. This is mathematically very easy to prove.

Encrypted application
XOR of this feature, so that it can be used to encrypt information.
Detailed operation XOR encryption
In the above code, the original information is Message, key is a key, the first encrypted text will be XOR cipherText. After the other side to get, and then do a key XOR operation, will be reduced to give the message.
Detailed operation XOR encryption

Perfect secrecy
during World War II, countries in order telegraph encryption, cryptography done a lot of research and practice, including XOR encryption.
After the war, the American mathematician Shannon published his research proved that as long as two conditions are met, XOR encryption is unbreakable.

the length of the key is greater than or equal Message
key must be disposable, and is generated randomly each time

The reason is simple, if every time the key is random, then CipherText has generated all possible values, and are evenly distributed and can not be seen from the CipherText any feature of message. In other words, it has the largest "information entropy" and therefore impossible to crack. This is called "perfect secrecy" XOR of (perfect secrecy).
The above two conditions are met key, called the one-time pad (abbreviated as the OTP), meaning "one-time pad", such as the previous cipher key are printed, each time use, which must be selected from key.

Guess you like

Origin www.cnblogs.com/shoshana-kong/p/11497494.html