whedesktop.blogg.se

Xor Encrypt Decrypt Php
Xor Encrypt Decrypt Php





Xor Encrypt Decrypt Php
  1. Xor Encrypt Decrypt Php how to#
  2. Xor Encrypt Decrypt Php password#

(1) The user name (clear text) and password (key) information is re-encrypted according to its submission, and the encrypted information is used to compare with the password information stored in the database, if it is equal, the user is legitimate, otherwise, it is an illegal user. In addition, there are two ways to authenticate a legitimate user when a user logs in. To achieve this, the XOR algorithm can be used to select the user name as plaintext, and the key is a user-defined password, and then the encrypted user name is stored in the database. The system can verify the legality of the user according to the password entered by the user.No one other than the user can obtain their password information, including system designers and database administrators.When the user registers, the user needs to add the user password form.In this example, in order to protect the user's password, the system wants to achieve the following purposes. The last two sections introduce the principle and implementation of information encryption/decryption using XOR operation, and the following will use this method to encrypt the user's login password. Using the XOR algorithm for authentication The results of the above example run as follows. Line 3rd defines a plaintext $my_password, and then defines the key $my_key on line 4th.ĥth, 6 lines call the encryption function to generate ciphertext and output, in turn, in the 7th, 8 will decrypt the ciphertext. Line 4th defines the decryption function mydecrypt (), the input parameter $string as ciphertext, and $key as the key, and the output is the plaintext that is generated using $key as the key and using the XOR decryption algorithm.īelow, a sample application is used to further illustrate the function of cryptographic functions.ĥ $my _password_en=myencrypt ($my _password, $my _key) Ħ echo "my_password_en = $my _password_en" ħ $my _password_de=mydecrypt ($my _password_en, $my _key) Ĩ echo "My_password_de = $my _password_de" Similarly, similar to cryptographic functions, the following decryption functions can be written.Ĩ $string = $key ^ $string

Xor Encrypt Decrypt Php

The principle has been introduced in the previous section and is not restated.

Xor Encrypt Decrypt Php

The outer for loop of line 6th to 12th loops through each character of the plaintext string, while the inner for Loop (line 8th to 11th) iterates over each character of the plaintext with each one of the keys. The 4th line defines the cryptographic function myencrypt (), the input parameter $string to clear text, and $key as the key, and the output is ciphertext that uses $key as the key and uses the XOR encryption algorithm. The encryption algorithm is listed first.ġ!-encrypy_xor: Simple cryptographic function with XOR operation-> Based on the principle of the XOR encryption algorithm introduced in the previous section, it is not difficult to write down the following cryptographic decryption functions.

Xor Encrypt Decrypt Php how to#

The previous section describes how to encrypt/decrypt using the XOR operation, which will be used to encrypt the user's login information. (3) For any character is valid, unlike some simple encryption algorithm, only valid for Western characters, the Chinese encryption and decryption can not be restored to the original character. (2) Fast, can be used at any time, anywhere. (1) The algorithm is simple and can be easily implemented for high-level languages. This algorithm is simple in principle and is designed to make readers have a more intuitive impression on the encryption/decryption of information.įrom the main method of encryption, the transposition method is too simple, especially for the case of less data, it is easy to guess the plaintext by ciphertext, and the substitution method is an effective and simple algorithm.įrom the characteristics of various substitution methods, the XOR operation is most suitable for simple addition and decryption operations, the principle of this method is: When a number A and another number B is an XOR operation will generate another number C, if the C and B are also the XOR operation, then C will revert to a.Ĭompared with other simple encryption algorithms, the XOR algorithm has the following advantages. This article describes an easy-to-use encryption/decryption algorithm that uses XOR (XOR) operations.







Xor Encrypt Decrypt Php