Skip to content

Commit

Permalink
增加了简单的加密解密算法
Browse files Browse the repository at this point in the history
  • Loading branch information
Iori-yimaga committed Aug 26, 2021
1 parent bc4f1fe commit 481a097
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
2 changes: 2 additions & 0 deletions KWBook.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,15 @@
<ClCompile Include="menu.cpp" />
<ClCompile Include="passwd_op.cpp" />
<ClCompile Include="permissionCheck.cpp" />
<ClCompile Include="secData.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="globalVals.h" />
<ClInclude Include="initializer.h" />
<ClInclude Include="menu.h" />
<ClInclude Include="passwd_op.h" />
<ClInclude Include="permissionCheck.h" />
<ClInclude Include="secData.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
6 changes: 6 additions & 0 deletions KWBook.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<ClCompile Include="permissionCheck.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="secData.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="menu.h">
Expand All @@ -47,5 +50,8 @@
<ClInclude Include="permissionCheck.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="secData.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>
8 changes: 2 additions & 6 deletions MyKeyBook.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
1 www.coolapk.com coolapk 123456
2 www.wechat.com 13207178976 123456
3 www.qq.com 964302865 123456
4 www.aliyun.com aliyun 123456
5 www.taobao.com taobao 123456
6 www.163.com 163613 123456
1 www.coolapk.com coolapk 032547
2 www.wechat.com wechat 032547
11 changes: 10 additions & 1 deletion passwd_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string.h>
#include <memory.h>
#include <conio.h>
#include "secData.h"

int g_Count = 0;
USERINFO myinfo = { 0 };
Expand Down Expand Up @@ -85,6 +86,9 @@ void addPasswd() {
}
myinfo.passWord[index] = '\0';

//加密数据
encryptData(myinfo.passWord);

// 写入数据
if (fprintf(fp, "%d\t%s\t%s\t%s\n", myinfo.ID, myinfo.webSite, myinfo.userName, myinfo.passWord)) {
printf("\n写入成功!\n");
Expand Down Expand Up @@ -150,6 +154,9 @@ void changePasswd() {

strcpy_s((pMyInfo + num - 1)->passWord, 20, arr);
for (int i = 0; i < g_Count; i++) {
// 加密密码
encryptData((pMyInfo + i)->passWord);

fprintf(fp, "%d\t%s\t%s\t%s\n", (pMyInfo + i)->ID, (pMyInfo + i)->webSite, (pMyInfo + i)->userName, (pMyInfo + i)->passWord);
}
printf("修改成功!\n");
Expand Down Expand Up @@ -179,9 +186,10 @@ void queryPasswd() {
PUSERINFO pMyInfo = (PUSERINFO)malloc(g_Count * sizeof(USERINFO));
for (int i = 0; i < g_Count; i++) {
fscanf_s(fp, "%d\t%s\t%s\t%s\n", &(pMyInfo + i)->ID, (pMyInfo + i)->webSite, 20, (pMyInfo + i)->userName, 20, (pMyInfo + i)->passWord, 20);
decryptData((pMyInfo + i)->passWord);
}
// 判断用户输入数字的界限
if (num > 0 && num < g_Count) {
if (num > 0 && num <= g_Count) {
printf("%d\t%s\t%s\t%s\n", (pMyInfo + num - 1)->ID, (pMyInfo + num - 1)->webSite, (pMyInfo + num - 1)->userName, (pMyInfo + num - 1)->passWord);
}
else {
Expand Down Expand Up @@ -209,6 +217,7 @@ void removePasswd() {
PUSERINFO pMyInfo = (PUSERINFO)malloc(g_Count * sizeof(USERINFO));
for (int i = 0; i < g_Count; i++) {
fscanf_s(fp, "%d\t%s\t%s\t%s\n", &(pMyInfo + i)->ID, (pMyInfo + i)->webSite, 20, (pMyInfo + i)->userName, 20, (pMyInfo + i)->passWord, 20);
decryptData((pMyInfo + i)->passWord);
}
fclose(fp);

Expand Down
29 changes: 29 additions & 0 deletions secData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "secData.h"
#include <stdio.h>
#include <stdlib.h>

/*
加密
@param char* 传入一个字符串
*/
void encryptData(char* str) {
int index = 0;
while (*(str + index) != '\0') {
*(str + index) |= -0x80;
*(str + index) ^= 0x1;
index++;
}
}

/*
解密
@param char* 传入一个字符串
*/
void decryptData(char* str) {
int index = 0;
while (*(str + index) != '\0') {
*(str + index) ^= 0x1;
*(str + index) ^= 0x80;
index++;
}
}
3 changes: 3 additions & 0 deletions secData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once
void encryptData(char* str);
void decryptData(char* str);

0 comments on commit 481a097

Please sign in to comment.