#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct sysuser
{
char username[20];
char password[8];
};
void encrypt(char *pwd);
int main()
{
FILE *fp;
int i;
struct sysuser su;
if ((fp = fopen("*f12-2.txt", "w")) == NULL)
{
printf("File open error!\n");
exit(0);
}
for (i = 1; i <= 5; i++)
{
printf("Enter %d th sysuser(name password):", i);
scanf("%s%s", su.username, su.password);
encrypt(su.password);
fprintf(fp, "%s%s\n", su.username, su.password);
}
if (fclose(fp))
{
printf("Can not close the file!\n");
exit(0);
}
return 0;
}
void encrypt(char *pwd)
{
int i;
for (i = 0; i < strlen(pwd); i++)
pwd[i] = pwd[i] ^ 15;
}
文件加密算法研究示例
最新推荐文章于 2025-07-11 16:13:27 发布
该程序使用C语言实现了一个简单的用户信息管理系统,将用户名和经过加密的密码写入到文件中。它首先定义了一个`sysuser`结构体,包含用户名和密码字段。然后通过循环读取用户输入的用户名和密码,调用`encrypt`函数对密码进行异或操作加密,并将结果保存到文件`f12-2.txt`。如果在文件操作过程中出现错误,程序会提示并退出。
443

被折叠的 条评论
为什么被折叠?



