XOR Key: 
  • Character Set:
  • Format:
    (Encrypted format represents output, decrypted format represents input)

Description

XOR: eXclusive OR, a logical operation, in addition to AND and OR, there is another operation called XOR, which stands for "exclusive OR".
Its definition is: returns false if two values are the same, otherwise returns true. In other words, XOR can be used to determine if two values are the same.

  
                true XOR true = false 
                false XOR false = false 
                true XOR false = true 
                false XOR true = true 
                

XOR has a wonderful property: if a value is XORed twice in a row, it will return the original value.

  
                // First XOR
                1010 XOR 1111 = 0101

                // Second XOR
                0101 XOR 1111 = 1010
                
It is this property that allows XOR to be used for information encryption.

During World War II, countries conducted extensive research and practice on cryptography for telegram encryption, including XOR encryption. After the war, American mathematician Claude Shannon publicly published his research results, proving that XOR encryption is unbreakable if two conditions are met:

  • The length of the key is greater than or equal to the message.
  • The key must be one-time, and must be generated randomly each time.
The reason is simple, if the key is random each time, then the generated CipherText has all possible values, and is uniformly distributed, making it impossible to deduce any characteristics of the message from the CipherText. In other words, it has the highest "information entropy," and therefore cannot be cracked. This is called XOR's "perfect secrecy."

A key that meets the above two conditions is called a one-time pad (OTP), meaning a "one-time password book," because in the past such keys were printed into password books, and one must select from them each time they are used.


Key(IV) Text Or Hex
  • Text represents the text format and is encoded in UTF-8 before being converted to a byte[] array.
  • Hex represents the hexadecimal format, and the input will be converted from a hexadecimal string to a byte[] array before encryption.
Character Set and Format encryption instructions
  • First Scenario, taking DES encryption as an example: select "Text" from the key dropdown, enter "12345678" as the Key, leave the IV empty; encrypt the string "中国abc". Choose character set "UTF-8". The encryption output is in hexadecimal format, select "Hex" from the format dropdown. The encrypted output result is "C886FF3D9DCB37FA1FA0EAD95889DF3E". View Example
  • Another Scenario, still using DES encryption as an example: select "Text" from the key dropdown, enter "12345678" as the Key, leave the IV empty; encrypt hexadecimal data, for example [0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08]. Choose character set "Hex". The encryption output is in Base64 format, select "Base64" from the format dropdown. The encrypted output result is "up/vqMd1Eq4d/TFcc22l3Q==". View Example
Character Set and Format decryption instructions
  • First Scenario, using DES decryption as an example: select "Text" from the key dropdown, enter "12345678" as the Key, leave the IV empty; decrypt the hexadecimal string "C886FF3D9DCB37FA1FA0EAD95889DF3E". Therefore, select "Hex" from the format dropdown for decryption, and the data encoding after decryption is "UTF-8". Choose character set "UTF-8". The decrypted string is "中国abc". View Example
  • Another Scenario, still using DES decryption as an example: select "Text" from the key dropdown, enter "12345678" as the Key, leave the IV empty; decrypt the Base64 string "up/vqMd1Eq4d/TFcc22l3Q==". Therefore, select "Base64" from the format dropdown for decryption, and there is no additional encoding after decryption, as it is hexadecimal data. Choose character set "Hex" (selecting "UTF-8" would result in garbled text). The final decrypted string is "0102030405060708". View Example