如何将单个字符转换为为基本密码哈希器设置整数,C++
How to convert individual chars to set integers for a basic password hasher, C++
我正在为一些 uni 工作制作密码哈希,这需要我获取一个输入的字符串,将其中的字符转换为整数(给定 a=1、b=2、c=3 等(并输出总和。
这就是我到目前为止所拥有的:一个将返回一个 int 的函数,它使用一个字符串从中转换为整数。但是我已经在尝试构建它时遇到了一些错误,我不知道如何从这里开始转换角色。
#include <iostream>
#include <string>
#include <windows.h>
#include <conio.h>
using namespace std;
int passHasher(string tempPassword)
{
int hashValue = 0; //function will return this at the end of the passes.
for (int i = 0; i < tempPassword.size; i++)
{
//hashing algorythm goes here.
}
}
干杯
欧文。
在C++中,字符可以作为其数值进行操作。例如,您可以执行以下操作:
char c = 'x';
int n = c - 'a'.
在这里,我以"x"为例。对于任何小写字母,n
将是介于 0 和 25 之间的数字(包括 0 和 25(。如果您想要 1 到 26,只需添加 1。
无法编译此代码的原因是没有定义 main 函数。添加后,您将在使用"size"方法时出现错误。大小是一种方法,因此最后需要 ((。
以下代码编译良好:
#include <iostream>
#include <string>
using namespace std;
int passHasher(string tempPassword)
{
int hashValue = 0; //function will return this at the end of the passes.
for (int i = 0; i < tempPassword.size(); i++)
{
//hashing algorythm goes here.
}
return 0;
}
int main() {
// get the string fromt the input and call function
}
我删除了windows.h,因为我使用的是Linux。在Windows上编译时,请随意添加它。
相关文章:
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 使用Qt C++计算类似Git的SHA1哈希
- CPP unordered_set只使用比较器而不是哈希
- 将私有结构哈希器运算符转换为静态
- 迭代器关系运算符出错(带单独链接和迭代器的自定义哈希表)
- 来自并发哈希映射的迭代器是否安全
- 如何将单个字符转换为为基本密码哈希器设置整数,C++
- MD5哈希的密码盐字符串的格式是什么?
- Win32 MD5哈希器的奇怪行为
- 简单的密码哈希程序 c++
- 创建密码的 SHA-256 哈希的 Botan 教程或示例
- 为密码哈希函数生成Salt的已接受方法-C++
- 使用加密哈希密码进行身份验证
- hash_set哈希器函数
- c++哈希函数对密码是否相当安全?
- 用于生成密码哈希的C/ c++函数(使用MD5或其他算法)
- 返回c++哈希表代码中的空迭代器
- (C++) 无法迭代密钥哈希器函数中的向量
- Tbb 并发哈希映射迭代器