排列生成

发布于 2024-10-05 22:01:48 字数 666 浏览 2 评论 0原文

今天,我团队的一些成员正在讨论密码存储和一般安全问题。不管怎样,讨论简要讨论了 GPU 加速的暴力攻击与传统的仅 CPU 实现相比有多快。

这引起了我的兴趣,所以我决定尝试一些代码。因为我以前从未写过这样的东西,所以我决定写一个简单的(仅 CPU)暴力破解器。我最初的实现涉及固定长度(4 位数字)密码。出于测试目的,我按照 la 的方式实现了它:

for(char a = '0'; a <= '9'; ++a)
{
  for(char b = '0'; b <= '9'; ++b)
  {
    for(char c = '0'; c <= '9'; ++c)
    {
      for(char d = '0'; d <= '9'; ++d)
      {
        candidate[0] = a; candidate[1] = b;
        candidate[2] = c; candidate[3] = d;

        // Test 'candidate'...
      }
    }
  }
}

这效果很好,但显然不灵活。我试图概括上述内容以处理任何密码长度,但未能做到这一点。出于某种原因,我无法理解这些暴力破解者在给定“字母表”的情况下运行 1-n 个字符可能性的逻辑。

是否有一些通用的算法可以帮助您完成此任务?欢迎任何例子。

Some members of my team were discussing password storage and general security issues today. Anyway, the discussion briefly touched upon how quick GPU-accelerated brute-force attacks are compared to the traditional CPU-only implementations.

This got me interested, so I decided to play around with some code. Since I've never written anything like this before, I decided to write a simple (CPU-only) brute-forcer. My initial implementation dealt with a fixed length (4 digit) password. For testing purposes, I implemented it a la:

for(char a = '0'; a <= '9'; ++a)
{
  for(char b = '0'; b <= '9'; ++b)
  {
    for(char c = '0'; c <= '9'; ++c)
    {
      for(char d = '0'; d <= '9'; ++d)
      {
        candidate[0] = a; candidate[1] = b;
        candidate[2] = c; candidate[3] = d;

        // Test 'candidate'...
      }
    }
  }
}

This works well, but is obviously inflexible. I attempted to generalize the above to handle any password length but have failed to do so. For some reason, I can't get my head around the logic that these brute-forcers use to run through 1-n character possibilities given an "alphabet".

Is there some common algorithm that allows you to accomplish this? Any examples welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苦笑流年记忆 2024-10-12 22:01:48

搜索引擎是你的朋友:)
C++ 暴力破解示例

(向下滚动一点..)

Search engines are your friends :)
C++ Brute force example

(Scroll down a little bit..)

违心° 2024-10-12 22:01:48

这是一个迭代版本......以下仅适用于小写字母,但可以轻松修改......

public static String nextLexographicWord(String txt)
{
    char [] letters = txt.toCharArray();
    int l = letters .length - 1;
    while(l >= 0)
    {
        if(letters[l] == 'z')
            letters[l] = 'a';
        else
        {
            letters[l]++;
            break;
        }
        l--;
    }
    if(l < 0) return 'a' + (new String(letters));
    return new String(letters); 
}

Here's a Iterative Version....The following works only for lowercase, but can easily be modified....

public static String nextLexographicWord(String txt)
{
    char [] letters = txt.toCharArray();
    int l = letters .length - 1;
    while(l >= 0)
    {
        if(letters[l] == 'z')
            letters[l] = 'a';
        else
        {
            letters[l]++;
            break;
        }
        l--;
    }
    if(l < 0) return 'a' + (new String(letters));
    return new String(letters); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文