C language implementation of simple text file encryption---Preliminary

Source: Internet
Author: User
Tags sprintf


First use Python to make a text file (a study number list)


Python code:

[email protected] kuing]# cat input.py

#!/usr/bin/env python

f = open (' Design.txt ', ' w+ ')

For I in Range (10001,200001):

F.write ('%d\n '%i)

F.close ()


Yes, that's so simple ...


And then there's these things.


...

199998

199999

200000


Next write the C language code:

[email protected] kuing]# cat input.c

#include <stdio.h>

#include <stdlib.h>

int main () {

FILE *FP;

FILE *temp;

Char filename[30];

Char ch;

Char strbuf[256];

printf ("Please input your filename:");

Gets (filename);

FILENAME[29] = ' \ n ';

if (fp = fopen (filename, "rb") = = = NULL) {

printf ("error!\n");

return-1;

}


if (temp = fopen ("Temp.txt", "wb+") = = = NULL) {

printf ("Create file error!\n");

}

while (!feof (FP)) {

ch = fgetc (FP);

if ((int) ch! = 0 && (int) ch! = 0) {

ch = ~ch;

CH = ch << 5;

FPUTC (ch,temp);

}

}

Fclose (temp);

Fclose (FP);

sprintf (Strbuf, "rm%s", filename);

System (STRBUF);

sprintf (Strbuf, "MV temp.txt%s", filename);

System (STRBUF);

return 0;

}


Then use the Linux system to compile with GCC when the get warning light ignore Linux is not recommended this writing

However, if you change to fgets () and solve the problem of symbols is more troublesome, please ignore:


And then run

Please enter the file you want to encrypt

[Email protected] kuing]#./input

Please input your filename:design.txt

...



After encryption is similar to this:


Φφφφφφφǐφǎφφφφǐφǐφǐφǐφǐφǎφǎφǎφωǎφχǎφǎφǎφǎφǎφǎφφφφφφφφφφφφφˋφˉφˇφφφφφφφφφφφφφφφφǐφǎφφφ ...



Actually, that's what this is about. If the program runs in turn, it will decrypt the contents of the string.


..

This article is from the "Kuing Home pages" blog, so be sure to keep this source http://kuing.blog.51cto.com/9635522/1759998

C language implementation of simple text file encryption---Preliminary

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.