Linux C's simplest encryption program

Source: Internet
Author: User
Tags bitwise decrypt

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.