程序基本思路.docx
- 文档编号:17942118
- 上传时间:2023-08-05
- 格式:DOCX
- 页数:10
- 大小:122.34KB
程序基本思路.docx
《程序基本思路.docx》由会员分享,可在线阅读,更多相关《程序基本思路.docx(10页珍藏版)》请在冰点文库上搜索。
程序基本思路
程序基本思路:
创建一个二进制文件,将密码保存在第一行,接着输入正文。
在输入密码与正文的同时将文件内容加密。
读取文件时要求输入密码,密码正确方允许将文本读出。
程序的优点:
在对密码进行读取的时候,并没有使用scanf函数,而是利用C语言嵌入汇编语言实现对机器低层的调用(int16和int21号调用),从而实现对输入密码的"*"化处理
存在问题:
(1) 加密函数过于简单(线性映射),可以采取更复杂的函数将字符等可能地散列到各个样本点处。
(2) 文件创建时没有支持ADT数据类型.
(3) 输入单个字符长度有限制.
运行界面:
图一:
输入0退出,1创建一个文件,2打开一个文件.在F盘下创建一个名为ttaikk的文件,密码设置为ttaikk
图二:
输入文本,以#字符结束。
图三:
输入密码并打开一个存在的文件。
/*Secure.c
Copyright(c)2002,2006byctu_85
AllRightsReserved.
*/
#include"stdio.h"
#include"string.h"
#defineright5
#definemaxpassword20
#defineminpassword6
#definemaxlen20
voidCreate();
voidLoad();
charsecure(char);
chardesecure(char);
voidmain()
{
intchoice;
printf("Pleaseenteryourchoice:
\n");
printf("0:
Toquit;\n");
printf("1:
Tocreateasecurityfile;\n");
printf("2:
Toloadasecurityfile.\n");
cir:
printf("Yourchoice:
");
scanf("%d",&choice);
if(choice==0)
return;
if(choice==1)
{
Create();
printf("\n");
gotocir;
}
else
if(choice==2)
{
Load();
printf("\n");
gotocir;
}
else
{
printf("Invalidinput!
\n");
gotocir;
}
}
voidCreate()
{
FILE*fp;
char*p,ch,s[maxpassword],*t,temp,path[maxlen];
recre:
printf("Pleaseenterthepathwhereyouwannathefiletobe:
");
scanf("%s",path);
p=path;
if(*p<'C'||*p>'F'||*(p+1)!
=':
'||*(p+2)!
=92||strlen(p)>30||strlen(p)<4)
{
printf("Invalidinput!
\n");
gotorecre;
}
if((fp=fopen(p,"wb"))==NULL)
{
printf("Error!
");
return;
}
printf("Pleaseenterthepassword:
");
an:
p=s;
lp:
_asm{
movah,00h
int16h
cmpal,0dh
jeexit
movtemp,al
movdl,'*'
movah,02h
int21h
}
*p=temp;
p++;
gotolp;
exit:
*p='\0';
p=s;
if(strlen(p)>maxpassword||strlen(p) { printf("Thepasswordistoolongortooshort,pleasereinput! \n"); gotoan; } while(*p! ='\0') { ch=*p; ch=secure(ch); p++; fputc(ch,fp); } ch='\n'; ch=secure(ch); fputc(ch,fp); printf("\nPleaseentertheinformation,endwithchar'#': "); ch=getchar(); ch=getchar(); while(ch! ='#') { ch=secure(ch); fputc(ch,fp); ch=getchar(); } ch=secure(ch); fputc(ch,fp); fclose(fp); } voidLoad() { FILE*fp; char*p,ch,s[maxpassword],tc,temp[maxpassword],pass[maxpassword],sign=secure('\n'); inti=0,t=0,lenth=0; rece: printf("Pleaseenterthepathwhereyouwannatoload: "); scanf("%s",p); if(*p<'C'||*p>'F'||*(p+1)! =': '||*(p+2)! =92||strlen(p)>30||strlen(p)<4) { printf("Invalidinput! \n"); gotorece; } if((fp=fopen(p,"rb"))==NULL) { printf("Error! "); return; } printf("Pleaseenterthepassword: "); an: p=s; lp: _asm{ movah,00h int16h cmpal,0dh jeexit movtc,al movdl,'*' movah,02h int21h } *p=tc; p++; gotolp; exit: *p='\0'; p=s; if(strlen(p)>maxpassword||strlen(p) { printf("Thepasswordistoolongortooshort,pleasereinput! \n"); gotoan; } while(*p! ='\0') { temp[i]=secure(*p); p++; i++; } temp[i]='\0'; printf("\n"); ch=fgetc(fp); while(ch! =sign) { pass[t]=ch; t++; ch=fgetc(fp); } pass[t]='\0'; ch=desecure(ch); if(! strcmp(temp,pass)) { while(ch! ='#') { ch=fgetc(fp); ch=desecure(ch); if(ch! ='#') putchar(ch); } } else printf("Thepasswordisincorrect! \n"); fclose(fp); } charsecure(charc) { if(c+right>254) returnc-255+right; else returnc+right; } chardesecure(charc) { if(c return255-right; else returnc-right; }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 程序 基本思路