File encryption and decryption algorithm C ++ txt word

Source: Internet
Author: User
# Include <stdio. h>
# Include <stdlib. h>
Int main ()
{
Int jiajie_fun (char infile [20], char outfile [20]); // Declaration of the encryption and decryption Function
Int choose;
Char mingfile [20];
Char mifile [20];
Printf ("welcome to the encryption and decryption File System \ n ");
While (1)
{
Printf ("Enter number 1 and press enter to enter the encryption system \ n ");
Printf ("Enter number 2 and press enter to enter the decryption system \ n ");
Printf ("select and enter 1 or 2 \ n ");
Scanf ("% d", & choose );
If (choose = 1 | choose = 2) break;
Printf ("if you have not entered the correct one, enter 1 or 2 and press enter to end. Please enter \ n" again ");
}
If (choose = 1)
{
Printf ("enter the name of the file you want to encrypt and press enter to end \ n ");
Scanf ("% s", mingfile );
Printf ("Enter the encrypted target file name and press enter to end \ n ");
Scanf ("% s", mifile );
Jiajie_fun (mingfile, mifile );
Printf ("the % s file has been encrypted successfully. Thank you for using this program \ n", mingfile );
}

If (choose = 2)
{
Printf ("enter the name of the file you want to decrypt and press enter to end \ n ");
Scanf ("% s", mifile );
Printf ("Enter the target file name to be decrypted, and press enter to end \ n ");
Scanf ("% s", mingfile );
Jiajie_fun (mifile, mingfile );
Printf ("decryption of the % s file has been successful. Thank you for using this program \ n", mifile );

}
Getchar ();
Getchar ();

}

Int jiajie_fun (char infile [20], char outfile [20])
{
Int key = 50; // 0 the number of digits that cannot be encrypted is not safe. However, in my personal opinion, the length is not the length, but the complexity determines the security.
// Float key = 3.14; // Replace the key if necessary
// Char key [] = "I am a goodboy ";
FILE * in, * out;
Char ch;

If (in = fopen (infile, "rb") = NULL)
{Printf ("this file \ n cannot be found ");
Exit (0);} // end the program
If (out = fopen (outfile, "wb") = NULL)
{Printf ("this file \ n cannot be found ");
Exit (0 );}

While (1)
{
Ch = fgetc (in );
Ch = ch ^ key; // It is good to use other more complex formulas here.
If (feof (in) break;
Fputc (ch, out );
}

Fclose (in );
Fclose (out );
Return 0;
}
// ********************************* Unique or encryption and decryption *** *******************************//
// ******************************** Embedded into File Reading **** **************************//
/* # Include <stdio. h>
Void main ()
{
Char ming [13] = "I am goodboy"; // '\ 0' plaintext
Int miyao = 356; // key
Char secret [13]; // The ciphertext size must be specified
For (int I = 0; I <13; I ++)
{* (Secret + I) = miyao ^ (* (ming + I);} // Encryption
Printf ("% s \ n", secret );
For (I = 0; I <13; I ++)
{* (Ming + I) = miyao ^ (* (secret + I);} // decrypt
Printf ("% s \ n", ming );
}*/

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.