您的位置 首页 > 数码极客

如何给txt设置密码

TXT文本加密

忘了是可以加密几兆以下的文本了,自己去看程序,好像是8m还是16m以下,加密个电子书绰绰有余了,加密完会生成一堆乱码,想要解密需要用程序将乱码改回来,程序很简单,但是很实用,有了它你可以放心地看小说,我们那个年代的苦楚,啧啧啧啧。觉得有用的,帮忙点个赞32位系统win-tc可以编译,64位win-tc不可用,64位系统可以用turbo-c编译,但是编译出的程序还得在32位系统下运行,64位系统想运行程序的话需要下载dosbox进行运行。

程序如下

1234.c:

-----------

/* HELLO.C -- Hello, world */

#include ";

#include "conio.h"

#include ";

#include "cjiami.c"

#include "cjiemi.c"

#include "ejiami.c"

#include "ejiemi.c"

#define BitGet ((ch & (1<<(7))) == (1<<(7))) /* 用来判断最高位是1还是0 */

main()

{

char ch;

void lock();

void unlock();

printf("lock a file,please enter 1\nunlock a file,please enter 2\n");

d: ch=getchar();

if(ch=='1') lock();

else if(ch=='2') unlock();

else

{

printf("please enter 1 or 2\n");

getch();

goto d;

}

}

void lock()

{

FILE *fp1,*fp2;

char infile[10],outfile[10],ch,key1[11],key2[11];

int j,d,pc;

long length,i ;

printf("please enter infile name:\n");

scanf("%s",infile);

if((fp1=fopen(infile,"r"))==NULL)

{printf("cannot open infile\n");

getch();

exit(0);

}

printf("please enter outfile name:\n");

scanf("%s",outfile);

if((fp2=fopen(outfile,"w"))==NULL)

{printf("cannot open outfile\n");

getch();

exit(0);

}

printf("please set your password(length<=10bit):\n");

scanf("%s",key1);

printf("please write your password again\n");

re: for(i=0;i<12;i++) /*初始化key2*/

key2[i]=0;

scanf("%s",key2);

for(i=0;key1[i]!='\0';i++)

if(key1[i]!=key2[i])

{

printf("password wrong,please rewrite it");

goto re;

}

if(key1[i]!=key2[i]) /*防止key1的\0不与key2的\0对应*/

{

printf("password wrongq,please rewrite it");

goto re;

}

length=i;

printf("password has been set rightly");

for(i=0;(ch=fgetc(fp1))!=EOF;i++)

{

d=key1[i%(length-1)]-48;

if(BitGet)

ch=cjiami(ch,d);

else if((ch>=33)&&(ch<=126)) ch=ejiami(ch,d);

fputc(ch,fp2);

}

fclose(fp1);

fclose(fp2);

getch();

}

void unlock()

{

FILE *fp1,*fp2;

char infile[10],outfile[10],key[11],ch;

int j,d,pc;

long length,i ;

printf("please enter infile name:\n");

scanf("%s",infile);

if((fp1=fopen(infile,"r"))==NULL)

{printf("cannot open infile\n");

getch();

exit(0);

}

printf("please enter outfile name:\n");

scanf("%s",outfile);

if((fp2=fopen(outfile,"w"))==NULL)

{printf("cannot open outfile\n");

getch();

exit(0);

}

printf("input password(length<=10bit)\n");

scanf("%s",key);

for(i=0;key[i]!='\0';i++);

length=i;

for(i=0;(ch=fgetc(fp1))!=EOF;i++)

{

d=key[i%(length-1)]-48;

if(BitGet)

ch=cjiemi(ch,d);

else if((ch>=33)&&(ch<=126)) ch=ejiemi(ch,d);

fputc(ch,fp2);

}

fclose(fp1);

fclose(fp2);

getch();

}

------------------------------------------------------------------------------

cjiami.c文件:

-------------

char cjiami(char ch,int d)

{ char ah;

int bh;

ah=ch-d;

return(ah);

}

------------------------------------------------------------------------------

cjiemi.c文件:

-------------

char cjiemi(char ch,int d)

{

char ah;

ah=ch+d;

return(ah);

}

------------------------------------------------------------------------------

ejiami.c文件:

-------------

char ejiami(char ch,int d)

{ char ah;

ah=ch-d;

if(ah<33) ah=ah+126-32;

return(ah);

}

------------------------------------------------------------------------------

ejiemi.c文件:

-------------

char ejiemi(char ch,int d)

{

char ah;

ah=ch+d;

if(ah>126) ah=ah-126+32;

return(ah);

}

-----------------------------------------------

作者:闲听落红不忍眠

责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“如何给txt设置密码”边界阅读