- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
好的,我正在为大学类(class)构建一个程序,这是一个简单的程序,它使用结构来模拟构建用户信息以及用户名和密码的数据库。对于实验室的额外学分,我们可以加密密码。这没什么特别的......我们没有使用 MD5 或类似的高级东西。
我需要做的就是能够将大写字符转换为小写,将小写字符转换为大写,最后是我遇到问题的部分,将十进制整数转换为十六进制。
我会尽量只发布程序的相关部分,而不是整个程序。
结构如下:
struct Info
{
string sFname;
string sLname;
string sUname;
string sPword;
string sAddress;
string sEmail;
string sPhone;
};
注意:这是一个结构体的动态数组
Info *Users;
Users = new Info[size];
这是加密我目前所拥有的密码的代码:
//string length for controlling loops
strlen = Users[iUsrCount].sPword.length();
//temp string to hold the encrypted version of password
string temp;
//switch uppercase characters to lowercase and vice versa, and convert
//decimal integers into hexadecimal
for(int i=0; i<strlen; i++)
{
cout << "\n\nInside encryption for loop iteration " << i << "\n\n";
if(islower(Users[iUsrCount].sPword[i]))
{
temp += toupper(Users[iUsrCount].sPword[i]);
continue;
}
else if(isupper(Users[iUsrCount].sPword[i]))
{
temp += tolower(Users[iUsrCount].sPword[i]);
continue;
}
else if(isdigit(Users[iUsrCount].sPword[i]))
{
char charNum = Users[iUsrCount].sPword[i];
int iDec = charNum - '0';
//get integer
while((i+1) < strlen && isdigit(Users[iUsrCount].sPword[i+1]))
{
i++;
iDec = iDec * 10 + Users[iUsrCount].sPword[i] - '0';
cout << " " << iDec << " ";
}
char hexTemp[10];
//convert
sprintf(hexTemp, "%x", iDec);
temp += hexTemp;
//debugging cout to make sure hexes are properly calculated
cout << " " << hexTemp << " ";
continue;
}
}
//debugging cout to make sure that password is properly encrypted
cout << endl << endl << temp << endl << endl;
strlen = temp.length();
//overwrite the plain text password with the encrypted version
for(int i=0; i<strlen; i++)
Users[iUsrCount].sPword[i] = temp[i];
//debugging cout to make sure copy was successful
cout << endl << endl << Users[iUsrCount].sPword;
所以如果您的密码是:
456Pass45word87
加密后看起来像这样:
1c8pASS2dWORD57
我们还必须反转字符串,但这相当简单。
我的两个问题是:
有没有更简单的方法来做到这一点?
我这辈子都无法找出正确的算法来解密密码,但我需要这样做,以便在用户登录时,计算机可以将他们键入的内容与纯文本进行比较他们密码的版本。
注意:我绝不是一个专业的编码员,所以请对菜鸟手下留情,不要对我太高级。我找遍了所有地方,但找不到任何对我的具体情况真正有帮助的东西。
因此,我将自己置于互联网的摆布之下。 :D
最佳答案
-- 我觉得你的方法不错。您的方法很清楚也很简单。
-- 你不应该尝试解密你的密码。用户登录时,使用加密后的密码进行比对。
关于c++ - 学校作业的简单密码加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19762006/
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
我是一名二年级的 ICT 学生。今年之前我从未接触过 PHP,我们的讲师给了我们基础知识,并在学期末给了我们一个项目,该项目将结合我们在他的类(class)和数据库类(class)中学到的知识。我们要
对于 JS 来说,我确实是个新手,而且我从学校收到了一个我无法理解的问题。我已经了解了一些,但非常感谢一些提示/帮助,因为我完全陷入困境! 它或多或少如下: 使用 HTML5 呈现一个网页,要求用户输
我对编程语言、django 和数据库模型相当陌生。所以我的问题很简单我在 models.py 中有 3 个模型 class UserProfileInfo(models.Model): # creat
是的,我知道 W3school,你们都讨厌它。我有时也会这样做,但现在它对我有帮助。如何为他们的网站制作删除 cookie 按钮?他们网站上的 cookie 示例: function setCo
我是一名优秀的程序员,十分优秀!