C language-based file encryption technology

Source: Internet
Author: User

I recently learned about file operations and felt that file encryption is still interesting. So I learned it carefully and made a simple summary. The following describes one of the methods-command encryption.

The command encryption method instructs the user to type a complete file name, including the file path and file name. For example, enter the encryption password to encrypt the specified file.

Principle of encryption: Read the characters in the file and write them to the new file. The decryption process is the same as the encryption principle.

ProgramWrite as follows:

# Include <stdio. h>

# Pragma hdrstop

# Include <tchar. h>

# Pragma argsused

Int _ tmain (INT argc, _ tchar * argv [])

{

File * file1, * file2;

Int I;

Int paslen;

Char ch;

Char source [30], DESTIN [30], password [10];

Printf ("Please input the source file (less than 30 charcters): \ n ");

Gets (source );

Printf ("Please input the destination file (less than 30 charcters): \ n ");

Gets (DESTIN );

Printf ("Please input the password (less than 10 ditigals): \ n ");

Gets (password );

Paslen = strlen (password); // get the password length

If (file1 = fopen (source, "rb "))! = NULL)

{

Printf ("the source file % s opened successfully. \ n", source );

If (file2 = fopen (DESTIN, "WB + "))! = NULL)

{

Printf ("the destination file % s created successfully \ n", DESTIN );

Ch = fgetc (file1 );

I = 0;

While (Ch! = EOF)

{

Ch = CH ^ (password [I ++]); // use the password for encryption

If (I> = paslen)

I = 0;

Fputc (CH, file2 );

Ch = fgetc (file1 );

}

Fclose (file1 );

Fclose (file2 );

}

Else

{

Printf ("the destination file % s created error \ n", DESTIN );

}

}

Else

{

Printf ("the source file % s opened error. \ n", source );

}

Getchar ();

Return 0;

}

the running result cannot be displayed. Sorry. I will send my summary to csdn.net. If necessary, I will download the summary. After all, it takes a long time to learn the summary, so I still need some points. Sorry, if you have any questions, please contact me. Thank you! The file contains three common encryption methods, including principles, algorithms , programs, and running results. More support! My csdn.net username is andamajing and the file name is "C language-based file encryption technology ".

Related Article

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.