📄 例3-4.c
字号:
/* Note:Your choice is C IDE */
#include <stdio.h>
#include <stdlib.h>
#define SIZE 64
void password(int fp,char *pd) /* 加密算法 */
{
int num,i,initread; /* initread是fseek函数的指定开始位置 */
long ig;
char *st,buf[SIZE];
st=pd;
ig=filelength(fp); /* 获取文件长度 */
while(ig>0)
{
initread=0;
num=fseek(fp,SIZE,initread);
if(num)
{
i=0;
while(*st&&(i<num)) /* 对SIZE个大小的字段加密处理 */
{
buf[i]=buf[i]^*st; /* 进行异或运算 */
st++;
i++;
}
}
initread+=SIZE; /* 向后移SIZE个大小 */
ig=ig-SIZE;
}
}
char *cmd,*pwd;
main()
{
char name1,buf[40];
int fp;
while(1)
{
getcwd(buf,40);
printf("%s>",buf);
gets(cmd);
printf("\n input filename that you want to lock or open:");
scanf("%s",name1);
if((fp=fopen(name1,"rb"))==NULL) /* 以只读方式打开一个二进制文件失败则退出 */
{
printf("File cannot be opened\n");
exit(1);
}
else /* 打开成功则加密 */
{
printf("File opened for encrpty\n");
printf("password:");
gets(pwd);
if(*pwd)
password(fp,pwd); /* 调用password函数加密 */
fclose(fp);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -