The initial password program was seen in Hirst first C, and the approximate contents are as follows:
Treats each character of the encrypted string with a numeric value one at a time, or gets ciphertext, and then makes a bitwise XOR or gets plaintext.
Supplementary knowledge: The result of the bitwise XOR is "the same position is 1, the ectopic is 0".
For example, the value 2 and the value 1 for the bitwise XOR situation as follows:
2 binary representation of the corresponding: 10
1 binary representation of the corresponding: 01
The results of the 2^1 final expression: 00
At this time, the results of the 2^1 and 1 are bitwise XOR or
01
00
10
The original encryption program is as follows:
#include <stdio.h>//Cryptographic Decryption ProgramvoidEncryptChar*message) { while(*message) { //bitwise XOR for each character and 31 of the message*message = *message ^ to; Message++; }}intMain () {CharS[] ="Hello Qizexi"; //Run Once: EncryptEncrypt (s); printf ("Encryption:%s\n", s); //To run again is to decryptEncrypt (s); printf ("decryption:%s\n", s); return 0;}
encrypt1.c
Since it is possible to make a bitwise XOR or encrypt a value, it is possible to make a bitwise XOR with a string.
The principle is as follows: Each character of the ciphertext to be encrypted and a key (arbitrary string) each character is one-time bitwise XOR or encrypted decryption.
The final key encryption procedure is as follows:
#include <stdlib.h>#include<string.h>#include<stdio.h>//Cryptographic Decryption ProgramvoidEncryptChar*message,Const Char*key) { inti; intLen =strlen (key); while(*message) { //bitwise XOR for each character and 31 of the message for(i =0; i < Len; i++) { *message = *message ^ (int) Key[i]; } Message++; }}intMain () {//Ciphertext CharS[] ="Hello Qizexi"; //secret key Char*key ="[email protected]"; //Run Once: EncryptEncrypt (s, key); printf ("Encryption:%s\n", s); //re-run: DecryptEncrypt (s, key); printf ("decryption:%s\n", s); return 0;}
encrypt2.c
How about not powder simple, feel the introduction of this program in your project.
Linux C's simplest encryption program