密码本(无bug版)
main.cpp #include <stdio.h>
#include <stdlib.h>
#include "data.h"
#include "ctrl.h" int main()
{
PPASSWORD pPwd = nullptr; // 密码数组
int nCount = ; // 当前密码个数
g_nNum = ; // 当前密码本容量 readInfo(&pPwd, &nCount); // 从本地文件中读取密码,用于初始化密码本 while (true)
{
system("title 欢迎使用密码本");
system("color 0E");
printf("**************************欢迎使用密码本****************************\n");
printf("* *\n");
printf("* --------------------------------- *\n");
printf("* | Powered By NoThx | *\n");
printf("* --------------------------------- *\n");
printf("* *\n");
printf("* 请输入你的选择 *\n");
printf("* 1)查看所有 *\n");
printf("* 2)新增密码 *\n");
printf("* 3)删除密码 *\n");
printf("* 4)修改密码 *\n");
printf("* 5)查询密码 *\n");
printf("* 6)生成文件 *\n");
printf("* 0)退出软件 *\n");
printf("* *\n");
printf("******************************************************************\n"); OPTION op;
scanf_s("%d", &op); switch (op)
{
case 查看所有:
searchAllInfo(pPwd, nCount);
break;
case 新增:
insertInfo(pPwd, &nCount);
break;
case 删除:
deleteInfo(pPwd, &nCount);
break;
case 修改:
alterInfo(pPwd, nCount);
break;
case 查询:
searchInfo(pPwd, nCount);
break;
case 保存文本:
SaveInfoA(pPwd, nCount);
break;
case 退出软件:
exit();
break;
default:
break;
}
} return ; }
data.h #pragma once //#define PWD_LEN 20 //密码最大长度 // 自定义数据类型
//定义所有的用户操作为枚举
enum OPTION {
#define 退出软件 0
#define 查看所有 1
#define 新增 2
#define 删除 3
#define 修改 4
#define 查询 5
#define 保存文本 6
#define 保存二进制 7
}; // 定义存储账号密码的结构体
typedef struct _PASSWORD
{
char website[]; // 站点名
char userName[]; // 用户名
char passWord[]; // 密码
char note[]; // 备注
}PASSWORD, *PPASSWORD; // 全局变量, 常量的声明
#define NUM 100 // 初始密码本的容量
extern int g_nNum; // 当前密码本容量
data.cpp #include "data.h" // 全局变量的定义
int g_nNum;
ctrl.h #pragma once //查看所有密码
void searchAllInfo(PASSWORD pwd[], int nCount); //新增密码
void insertInfo(PASSWORD pwd[], int *pnCount); //删除密码
void deleteInfo(PASSWORD pwd[], int * pnCount); //修改密码
void alterInfo(PASSWORD pwd[], int nCount); //查询密码
void searchInfo(PASSWORD pwd[], int nCount); // 保存密码(文本方式)
void SaveInfoA(PASSWORD pwd[], int nCount); //保存密码(二进制的方式)
void SaveInfoB(PASSWORD pwd[], int nCount); //从本地文件中读取密码,用于初始化密码本
void readInfo(PPASSWORD *ppPwd, int * pnCount);// 传递指针是因为希望函数在内部改变这个变量的值
ctrl.cpp #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "data.h" // 函数声明,否则保存不可用
void SaveInfoB(PASSWORD pwd[], int nCount); //查看所有密码
void searchAllInfo(PASSWORD pwd[], int nCount)
{
printf("==共计:%3d 条记录=====================\n", nCount);
for (int i = ; i < nCount; i++)
{
printf("--ID:%3d---------------------\n", i);
printf("目标:%s \n", pwd[i].website);
printf("用户名:%s \n", pwd[i].userName);
printf("密码:%s \n", pwd[i].passWord);
printf("备注: %s \n", pwd[i].note);
} printf("\n");
system("pause");
system("cls");
} //新增密码
void insertInfo(PASSWORD pwd[], int *pnCount)
{
int i = *pnCount;
if (i < || i >= NUM)
{
printf("插入位置异常:%d \n", i);
return;
}
printf("请输入<目标站点>\n");
scanf_s("%s", pwd[i].website, );
printf("请输入<用户名>\n");
scanf_s("%s", pwd[i].userName, );
printf("请输入<密码>\n");
scanf_s("%s", pwd[i].passWord, );
printf("请输入<备注信息>\n");
scanf_s("%s", pwd[i].note, ); (*pnCount)++; SaveInfoB(pwd, *pnCount); printf("\n");
system("pause");
system("cls"); } //删除密码
void deleteInfo(PASSWORD pwd[], int * pnCount)
{
int i = -;
printf("请输入待删除项<密码ID>\n");
scanf_s("%d", &i);
if (i < || i >= NUM)
{
printf("删除位置异常:%d \n", i);
return;
} for (int j = i; j < *pnCount - ; j++)
{
pwd[j] = pwd[j + ];
} (*pnCount)--; SaveInfoB(pwd, *pnCount); printf("\n");
system("pause");
system("cls");
} //修改密码
void alterInfo(PASSWORD pwd[], int nCount)
{
int i = -;
printf("请输入待修该项<密码ID>\n");
scanf_s("%d", &i);
if (i < || i >= NUM)
{
printf("修改位置异常:%d \n", i);
return;
} printf("--ID:%3d---------------------\n", i);
printf("目标:%s \n", pwd[i].website);
printf("用户名:%s \n", pwd[i].userName);
printf("密码:%s \n", pwd[i].passWord);
printf("备注: %s \n", pwd[i].note);
printf("~修改~\n"); printf("请输入<目标站点>\n");
scanf_s("%s", pwd[i].website, );
printf("请输入<用户名>\n");
scanf_s("%s", pwd[i].userName, );
printf("请输入<密码>\n");
scanf_s("%s", pwd[i].passWord, );
printf("请输入<备注信息>\n");
scanf_s("%s", pwd[i].note, ); SaveInfoB(pwd, nCount); printf("\n");
system("pause");
system("cls");
} //查询密码
void searchInfo(PASSWORD pwd[], int nCount)
{
char key[] = { };
printf("请输入查找密码的关键字:\n");
scanf_s("%s", key, ); // 找出所有匹配项
int findPwd[] = { };
int nfindCount = ;
for (int i = ; i < nCount; i++)
{
if (strstr(pwd[i].website, key))
{
findPwd[nfindCount++] = i;
continue;
}
if (strstr(pwd[i].userName, key))
{
findPwd[nfindCount++] = i;
continue;
}
if (strstr(pwd[i].passWord, key))
{
findPwd[nfindCount++] = i;
continue;
}
if (strstr(pwd[i].note, key))
{
findPwd[nfindCount++] = i;
continue;
}
} //打印所有匹配项
printf("==共计匹配:%3d 条记录===================\n", nfindCount);
for (int i = ; i < nfindCount; i++)
{
int pos = findPwd[i];
printf("--ID:%3d----------------------\n", pos);
printf("目标:%s \n", pwd[pos].website);
printf("用户名:%s \n", pwd[pos].userName);
printf("密码:%s \n", pwd[pos].passWord);
printf("备注:%s \n", pwd[pos].note);
} printf("\n");
system("pause");
system("cls");
} // 保存密码(文本方式)
void SaveInfoA(PASSWORD pwd[], int nCount)
{
/*
读写文件的固定套路
1. 打开文件
2. 读写文件
3. 关闭文件
*/ // 打开文件
FILE *pFile;
errno_t err = fopen_s(&pFile, "data.txt", "w");
if (err != )
{
return;
} // 读写文件
fprintf(pFile, "==共计:%3d 条记录==================\n", nCount);
for (int i = ; i < nCount; i++)
{
fprintf(pFile, "目标: %s \n", pwd[i].website);
fprintf(pFile, "用户名: %s \n", pwd[i].userName);
fprintf(pFile, "密码: %s \n", pwd[i].passWord);
fprintf(pFile, "备注: %s \n", pwd[i].note);
} // 关闭文件
fclose(pFile);
printf("保存文本密码成功,使用后请尽快删除!!\n");
system("pause");
system("cls");
} //保存密码(二进制的方式)
void SaveInfoB(PASSWORD pwd[], int nCount)
{
// 打开文件
FILE *pFile;
errno_t err = fopen_s(&pFile, "data.i", "wb");
if (err != )
{
return;
} // 读写文件
fwrite(&nCount, sizeof(nCount), , pFile); // 当前密码个数
fwrite(&g_nNum, sizeof(g_nNum), , pFile); // 当前密码本容量(个数) //先加密(使用中间文件),在存储
int byteSize = sizeof(PASSWORD) * g_nNum;
char *buf = (char *)malloc(byteSize);
memcpy_s(buf, byteSize, pwd, byteSize); for (int i = ; i < byteSize; i++)
{
buf[i] ^= (i + nCount + g_nNum);
}
size_t rlen = fwrite(buf, sizeof(PASSWORD), g_nNum, pFile); // 密码数组
if (rlen != g_nNum)
{
printf("写入密码文件错误\n");
}
else
{
printf("成功!!\n");
} // 关闭文件
fclose(pFile);
free(buf);
} //从本地文件中读取密码,用于初始化密码本
void readInfo(PPASSWORD *ppPwd, int * pnCount)
{
// 打开文件
FILE *pFile;
errno_t err = fopen_s(&pFile, "data.i", "rb");
if (err != )
{
*ppPwd = (PPASSWORD)malloc(sizeof(PASSWORD) * NUM);
g_nNum = NUM;
return;
} // 读写文件
// 先读取,再解密
fread(pnCount, sizeof(int), , pFile); // 当前密码个数
fread(&g_nNum, sizeof(g_nNum), , pFile); //当前密码本容量(个数)
*ppPwd = (PPASSWORD)malloc(sizeof(PASSWORD) * g_nNum);
memset(*ppPwd, , sizeof(PASSWORD)*g_nNum);
size_t rlen = fread(*ppPwd, sizeof(PASSWORD), g_nNum, pFile); // 密码数组 if (rlen != g_nNum)
{
printf("读取密码文件错误 \n");
fclose(pFile);
return;
} // typedef unsigned int size_t; int byteSize = sizeof(PASSWORD)*g_nNum;
char *buf = (char *)*ppPwd;
for (int i = ; i < byteSize; i++)
{
buf[i] ^= (i + *pnCount + g_nNum);
} // 关闭文件
fclose(pFile);
}
运行结果如下:

密码本(无bug版)的更多相关文章
- 【资源】C++学习资料 - 逆天整理 - 精华无密版【最新】
再失效就太无语了,链接都是多份的~~—————————————————基础——————————————C++环境搭建(全套)http://pan.baidu.com/s/1o6y0smY链接:http ...
- 漫谈程序猿系列:无BUG不生活
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZm9ydW9r/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...
- 【web 安全测试Tools】BurpSuite 1.7.32及注册机【无后门版】
BurpSuite 1.7.32 原版+注册机 下载 链接:https://pan.baidu.com/s/1LFpXn2ulTLlcYZHG5jEjyw 密码:mie3 注意无后门版文件完整性: b ...
- 佛祖保佑 永无bug
/* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : | ...
- 佛祖保佑,永无bug
/* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : | ...
- 佛祖保佑 永无BUG 永不修改
// // _oo0oo_ // o8888888o // 88" . "88 // (| -_- |) // 0\ = /0 // ___/`---'\___ // .' \\| ...
- 职业卖家淘宝美工教程,掌握技能无师自通 学到的不只是PS(共81节)附素材【无水印版】
职业卖家淘宝美工教程,掌握技能无师自通 学到的不只是PS(共81节)附素材[无水印版]设计传说出品的专业课程是我们资深培训讲师精心录制的,只有视频教程和常用必备的插件,其他绝不掺和,如果你是职业卖家, ...
- 佛主保佑,永无bug
/* _ooOoo_ o8888888o 88" . "88 ...
- 佛祖保佑 永无BUG(网转 by atkfc)
// _ooOoo_ // o8888888o // 88" . ...
随机推荐
- springBoot配置分析(属性和结构化)
使用idea自带插件创建项目 一直下一步到完成 application.properties local.ip.addr = 192.168.2.110 redis.host = 192.168.3. ...
- 【题解】51nod 1203JZPLCM问题
这题好强强啊,貌似是集训队原题?集训队原题当中值域是1e9的范围,这样各种乱搞是妥妥的不能过了,只能写正解的离线+树状数组维护前缀积. 最开始我写了几种乱搞做法,包括莫队和线段树做法.其中表现比较优秀 ...
- BZOJ2875 & 洛谷2044:[NOI2012]随机数生成器——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=2875 https://www.luogu.org/problemnew/show/P2044 栋栋 ...
- BZOJ3224:普通平衡树——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=3224 题面源于洛谷 题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下 ...
- [Leetcode] single number ii 找单个数
Given an array of integers, every element appears three times except for one. Find that single one. ...
- call和apply第一个参数为null/undefined,函数this指向全局对象
call和apply第一个参数为null/undefined,函数this指向全局对象,在浏览器中是window,在node中是global 在严格模式中(ie 6/7/8/9 除外),传入null/ ...
- AES encryption of files (and strings) in java with randomization of IV (initialization vector)
http://siberean.livejournal.com/14788.html Java encryption-decryption examples, I've seen so far in ...
- C++分离字符串中的数字和字符 转
#include <iostream> #include <string> #include <vector> using namespace std; void ...
- 剑桥offer(31~40)
31.题目描述 统计一个数字在排序数组中出现的次数. 思路:找到最低和最高,相减 class Solution { public: int GetNumberOfK(vector<int> ...
- Python通过PhantomJS获取JS渲染后的网页源代码
新建一个文件,命名为test.js,内容如下: var page = require('webpage').create(), system = require('system'), address; ...