C++:反转这个散列?

C++: Reverse this hash?

我一直在使用它来散列我的密码,但我感觉它不是很安全。我一直在谷歌搜索,看看是否有人使用它解密了一个字符串。这是加密算法,我不确定如何通过反转数学来解密哈希。欢迎任何帮助。这是 C++ 中的加密器。

编辑:我确实计划切换到一种更安全的哈希密码方法,但是为了做到这一点,我需要在转换为新的哈希 SHA256 字符串之前反转数学以将其转换为纯文本。人们在这里似乎不理解我,我知道这是不安全的,这只是用 c++ 展示算法。它实际上是针对不同的语言。我在该语言中能做什么以及如何做是有限的。

#include <iostream>
#include <string.h>
using namespace std;



int main()
{
    char hasher[256];
    cout<< "Input a string!"<<endl;
    cin>> hasher;
    cout << endl;


for(int x=0; x < strlen(hasher); x++)
  {
      hasher[x] += (3^x) * (x % 15);
      if(hasher[x] > (255))
      {
          hasher[x] -= 256;
      }
  }

  cout << hasher << endl;
  system("pause");
  return 1;
}

您修改每个字符,only based on its relative position in the string. This is an extremely weak way to proceed. It won't resist a plain text attack(如果您知道两个密码及其编码):

password  ->  pcusôìÉÇ
abaaa     ->  adca}

因此攻击者会立即注意到第一个和第四个字符保持不变,第二个和第三个字符移动了2个字母。对于平均 8 个字母的密码,其中一半会被破解。不幸的是,许多密码可能会根据前四个字母被猜到!

事实上,用这种方法很容易找出其他班次 0,2,2,0,28, 30,30,28,88,80,90,....(不如印象深刻你的公式,不是吗?)。

您将您的用户真正置于危险之中。更好的是,使用标准哈希函数 such as sha512 and store only the hash in the database. This means that it's not possible to find back the password (missing information). But you can verify if the password the user typed is correct by calculating the hash of its input and compare it to the hash in the database (see "article Safely storing user passwords")。

您正在根据位置为角色添加一个数字。减去那个数字 3^x etc