📄 crypt.cpp
字号:
#include "stdio.h"
#include "string.h"
#define right 5
#define maxpassword 20
#define minpassword 6
#define maxlen 20
void Create();
void Load();
char secure(char);
char desecure(char);
void main()
{
int choice;
printf("Please enter your choice:\n");
printf("0:To quit;\n");
printf("1:To create a security file;\n");
printf("2:To load a security file .\n");
cir:
printf("Your choice:");
scanf("%d",&choice);
if(choice==0)
return;
if(choice==1)
{
Create();
printf("\n");
goto cir;
}
else
if(choice==2)
{
Load();
printf("\n");
goto cir;
}
else
{
printf("Invalid input!\n");
goto cir;
}
}
void Create()
{
FILE *fp;
char *p,ch,s[maxpassword],*t,temp,path[maxlen];
recre:
printf("Please enter the path where you wanna the file to be:");
scanf("%s",path);
p=path;
if(*p<'C'||*p>'F'||*(p+1)!=':'||*(p+2)!=92||strlen(p)>30||strlen(p)<4)
{
printf("Invalid input!\n");
goto recre;
}
if((fp=fopen(p,"wb"))==NULL)
{
printf("Error!");
return;
}
printf("Please enter the password:");
an:
p=s;
lp:
_asm {
mov ah,00h
int 16h
cmp al,0dh
je exit
mov temp,al
mov dl,'*'
mov ah,02h
int 21h
}
*p=temp;
p++;
goto lp;
exit:
*p='\0';
p=s;
if(strlen(p)>maxpassword||strlen(p)<minpassword)
{
printf("The password is too long or too short,please reinput!\n");
goto an;
}
while(*p!='\0')
{
ch=*p;
ch=secure(ch);
p++;
fputc(ch,fp);
}
ch='\n';
ch=secure(ch);
fputc(ch,fp);
printf("\nPlease enter the information,end with char '#':");
ch=getchar();
ch=getchar();
while(ch!='#')
{
ch=secure(ch);
fputc(ch,fp);
ch=getchar();
}
ch=secure(ch);
fputc(ch,fp);
fclose(fp);
}
void Load()
{
FILE *fp;
char *p,ch,s[maxpassword],tc,temp[maxpassword],pass[maxpassword],sign=secure('\n');
int i=0,t=0,lenth=0;
rece:
printf("Please enter the path where you wanna to load:");
scanf("%s",p);
if(*p<'C'||*p>'F'||*(p+1)!=':'||*(p+2)!=92||strlen(p)>30||strlen(p)<4)
{
printf("Invalid input!\n");
goto rece;
}
if((fp=fopen(p,"rb"))==NULL)
{
printf("Error!");
return;
}
printf("Please enter the password:");
an:
p=s;
lp:
_asm {
mov ah,00h
int 16h
cmp al,0dh
je exit
mov tc,al
mov dl,'*'
mov ah,02h
int 21h
}
*p=tc;
p++;
goto lp;
exit:
*p='\0';
p=s;
if(strlen(p)>maxpassword||strlen(p)<minpassword)
{
printf("The password is too long or too short,please reinput!\n");
goto an;
}
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("The password is incorrect!\n");
fclose(fp);
}
char secure(char c)
{
if(c+right>254)
return c-255+right;
else
return c+right;
}
char desecure(char c)
{
if(c<right)
return 255-right;
else
return c-right;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -