生成巨大单词列表的算法

发布于 2024-08-10 10:57:23 字数 465 浏览 7 评论 0原文

好吧,我知道这听起来很糟糕,就像我要用它来做不道德的事情,但我向你保证,我不会。

我正在为我的计算机和信息安全课程写一篇论文,我选择的主题是哈希方法。我在论文中讨论的要点之一是 MD5 只是单向的,破解 MD5 哈希值的唯一方法是不断创建字符串并使用 MD5 函数,然后将其与要破解的哈希值进行比较。

我想构建一个非常简单的模型程序来与我的论文一起展示(我们做了一个演示,这将是一件很棒的事情),所以我想制定一种算法,用每个可能的字符组合来生成一个字符串最多 8 个字符。例如,输出将是:

a、b、c、...、aa、ab、ac、...ba、bb、bc 等等。

如果可能,它需要包含字母、数字和符号。

我已经部分完成了这个算法,但不幸的是我的编程技能无法胜任这项任务。如果有人能为此提供完整的算法,我将非常感激。

再说一次,如果您认为我是个骗子并且我将使用它来进行黑客攻击,您不必留下答案。

谢谢。 :)

Alright, I know this is going to sound bad, like I'm going to use this for un-ethical things, but you have my word that I am not.

I am writing a paper for my Computer and Information Security course and the topic I chose was hashing methods. One of the points that I go over in my paper is MD5 being only one-way and the only way to crack an MD5 hash is to continuously make strings and use an MD5 function, then compare it with the hash you want to crack.

I would like to build a really simple mock-up program to show alongside my paper (we do a presentation and this would be an awesome thing to have), so I wanted to work out an algorithm that makes a string with every possible character combination up to 8 characters. For example the output will be:

a, b, c, ..., aa, ab, ac, ... ba, bb, bc etc etc etc.

It need to include letters, numbers and symbols if possible.

I got partly through the algorithm for this, but unfortunately my programming skills are not up to the task. If anyone can provide a complete algorithm for this I'd be extremely thankful.

Again, if you think I'm a liar and I'm going to use this for hacking purposes you don't have to leave an answer.

Thank you. :)

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

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

发布评论

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

评论(5

浅唱ヾ落雨殇 2024-08-17 10:57:23

在 Python 中, itertools.product 几乎可以满足您的所有需求 -尽管它只执行一次“重复次数”,所以您必须从 1 迭代到 8(并不难;-)。本质上:

import itertools
import string

# whatever you wish as alphabet (lower/upper, digits, punct, &c)
myalphabet = string.ascii_lowercase + string.ascii_digits

def prods(maxlen, alphabet=myalphabet):
  for i in range(1, maxlen+1):
    for s in itertools.product(alphabet, repeat=i):
      yield ''.join(s)

当然,对于长度为 N 和 K 次重复的字母表(在您的情况下为 8 次),这确实会产生 N + N^2 + ... + N^K 种可能性(N=36 和 K=8 时有 2,901,713,047,668 种可能性) ,但是,朋友之间的几万亿输出算什么!-)

In Python, itertools.product does almost all you require -- though it does it for just one "number of repeats", so you'll have to iterate from 1 to 8 (not hard;-). In essence:

import itertools
import string

# whatever you wish as alphabet (lower/upper, digits, punct, &c)
myalphabet = string.ascii_lowercase + string.ascii_digits

def prods(maxlen, alphabet=myalphabet):
  for i in range(1, maxlen+1):
    for s in itertools.product(alphabet, repeat=i):
      yield ''.join(s)

Of course, for an alphabet of length N and K repetitions (8 in your case) this does produce N + N^2 + ... + N^K possibilities (2,901,713,047,668 possibilities for N=36 and K=8), but, what's a few trillion outputs among friends!-)

月寒剑心 2024-08-17 10:57:23

为了实现这个,我可能会将整数编码为基数 36(或者更多,如果你想要符号)。

1 = 1
2 = 2
...
一 = 10
b = 12
..

等等。

那么你会有一个数字,比如 38 并进行一些除法,即:

38/36 = 1 remaider 2 = 12 in base 36

然后只需运行一个 for 循环到你想要编码的最大数字,一些非常大的数字并输出你的编码数字。

只是为了好玩,我为你写了这个: http://pastebin.antiyes.com/index .php?id=327

To implement this i would probably encode integers to base 36 (or more if you wanted symbols).

1 = 1
2 = 2
...
a = 10
b = 12
..

and so on.

then you would have a number, like 38 and do some divisions, ie:

38/36 = 1 remaider 2 = 12 in base 36

then just run a for loop to your max number you want to encode, something very large and output your encoded numbers.

just for fun i wrote this for you: http://pastebin.antiyes.com/index.php?id=327

很酷又爱笑 2024-08-17 10:57:23

“破解 MD5 哈希值的唯一方法”并不是生成每个可能的字符串并查找冲突。事实上,如果您有权访问原始文件,则可以对其进行修改,使其 MD5 与您可以创建的另一个文件的 MD5 相匹配。 infosec.edu 上的一篇论文

即使您无法修改原始文件,也存在MD5校验和的彩虹表,可用于产生碰撞。

这些事实使得 MD5 不适合密码或密码学,事实上,美国政府已禁止其继续用于安全应用程序。

It is not true that "the only way to crack an MD5 hash" is to generate every possible string and look for collisions. In fact, if you have access to the original it is possible to modify it so that its MD5 matches that of another file you can create. This is described in a paper at infosec.edu.

Even if you cannot modify the original file, rainbow tables of MD5 checksums exist which can be used to generate collisions.

These facts make MD5 unsuitable for passwords or cryptography, and in fact the U.S. government has forbidden its continued use for secure applications.

二货你真萌 2024-08-17 10:57:23

如果您已经可以访问密码的哈希版本,则 MD5 会被破坏< /a>.也就是说,当涉及到破坏哈希值时,您可能最好使用 Rainbow Tables、字典攻击社会工程优于暴力方法。也就是说,既然您要求一种算法来生成所有值,也许以下内容会有所帮助(C#):

using System;
using System.Text;

namespace PossibiltyIterator
{
  class Program
  {
    static readonly char[] Symbols = {
      'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 
      'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 
      'I', 'J', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 
      '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '@', '#', '

说实话,这可以进一步优化。因为它构建了长度为 1 的所有“单词”,然后在构建长度为 2 的单词时再次起作用。构建长度为 MaxLength 的单词,然后截断一个字母以构建 MaxLength 的单词会更聪明- 1.

这是优化版本...请注意,它不会按最初请求的顺序返回单词。

using System;
using System.Text;

namespace PossibiltyIterator
{
  class Program
  {
    static readonly char[] Symbols = {
      'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 
      'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 
      'I', 'J', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 
      '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '@', '#', '
, '%', '^', '&', 
      '*', '(', ')', '-', '_', '+', '=', '/', '\\', '[', ']', '{', '}', ';', ':', '\'', '"', 
      ',', '.', '<', '>', '?', '`', '~'
    };

    const int MaxLength = 8;

    static void BuildWord(int currentLength, int desiredLength, char[] word)
    {
      if (currentLength == desiredLength)
      {
        Console.WriteLine(word);
      }
      else
      {
        for (int value = 0; value < Symbols.Length; ++value)
        {
          word[currentLength] = Symbols[value];
          BuildWord(currentLength + 1, desiredLength, word);
        }
      }
    }

    static void Main(String[] args)
    {
      double totalValues = (Math.Pow(Symbols.Length, MaxLength + 1) - Symbols.Length)/(Symbols.Length - 1);
      Console.WriteLine("Warning! You are about to print: {0} values", totalValues);
      Console.WriteLine("Press any key to continue...");
      Console.ReadKey(true /* intercept */);

      for (int desiredLength = 1; desiredLength <= MaxLength; ++desiredLength)
      {
        BuildWord(0 /* currentLength */, desiredLength, new char[MaxLength]);
      }
    }

  }
}

说实话,这可以进一步优化。因为它构建了长度为 1 的所有“单词”,然后在构建长度为 2 的单词时再次起作用。构建长度为 MaxLength 的单词,然后截断一个字母以构建 MaxLength 的单词会更聪明- 1.

这是优化版本...请注意,它不会按最初请求的顺序返回单词。


, '%', '^', '&', 
      '*', '(', ')', '-', '_', '+', '=', '/', '\\', '[', ']', '{', '}', ';', ':', '\'', '"', 
      ',', '.', '<', '>', '?', '`', '~'
    };

    const int MaxLength = 8;

    static void BuildWord(int currentLength, int desiredLength, char[] word)
    {
      if (currentLength != desiredLength)
      {
        for (int value = 0; value < Symbols.Length; ++value)
        {
          word[currentLength] = Symbols[value];
          BuildWord(currentLength + 1, desiredLength, word);
        }
        word[currentLength] = '\0';
      }

      Console.WriteLine(word);
    }

    static void Main(String[] args)
    {
      double totalValues = (Math.Pow(Symbols.Length, MaxLength + 1) - Symbols.Length)/(Symbols.Length - 1);
      char[] word = new char[MaxLength];

      Console.WriteLine("Warning! You are about to print: {0} values", totalValues);
      Console.WriteLine("Press any key to continue...");
      Console.ReadKey(true /* intercept */);

      BuildWord(0 /* currentLength */, MaxLength, new char[MaxLength]);
    }

  }
}
, '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', '/', '\\', '[', ']', '{', '}', ';', ':', '\'', '"', ',', '.', '<', '>', '?', '`', '~' }; const int MaxLength = 8; static void BuildWord(int currentLength, int desiredLength, char[] word) { if (currentLength == desiredLength) { Console.WriteLine(word); } else { for (int value = 0; value < Symbols.Length; ++value) { word[currentLength] = Symbols[value]; BuildWord(currentLength + 1, desiredLength, word); } } } static void Main(String[] args) { double totalValues = (Math.Pow(Symbols.Length, MaxLength + 1) - Symbols.Length)/(Symbols.Length - 1); Console.WriteLine("Warning! You are about to print: {0} values", totalValues); Console.WriteLine("Press any key to continue..."); Console.ReadKey(true /* intercept */); for (int desiredLength = 1; desiredLength <= MaxLength; ++desiredLength) { BuildWord(0 /* currentLength */, desiredLength, new char[MaxLength]); } } } }

说实话,这可以进一步优化。因为它构建了长度为 1 的所有“单词”,然后在构建长度为 2 的单词时再次起作用。构建长度为 MaxLength 的单词,然后截断一个字母以构建 MaxLength 的单词会更聪明- 1.

这是优化版本...请注意,它不会按最初请求的顺序返回单词。

If you already have access to the hashed version of the password, then MD5 is broken to begin with. That said, when it comes to breaking a hashed value, you'd likely be better off using Rainbow Tables, Dictionary Attacks, and Social Engineering over your brute force method. That said, since you asked for an algorithm to generate all the values, maybe the following will be beneficial (C#):

using System;
using System.Text;

namespace PossibiltyIterator
{
  class Program
  {
    static readonly char[] Symbols = {
      'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 
      'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 
      'I', 'J', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 
      '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '@', '#', '

To be completely honest, this can be optimized further. Because it builds all the "words" of length 1, then does that work a second time in building the words of length 2. It would be smarter to build the words of length MaxLength, then truncate one letter to build a word of MaxLength-1.

Here is the optimized version... note that it does NOT return the words in the order originally requested.

using System;
using System.Text;

namespace PossibiltyIterator
{
  class Program
  {
    static readonly char[] Symbols = {
      'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 
      'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 
      'I', 'J', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 
      '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '@', '#', '
, '%', '^', '&', 
      '*', '(', ')', '-', '_', '+', '=', '/', '\\', '[', ']', '{', '}', ';', ':', '\'', '"', 
      ',', '.', '<', '>', '?', '`', '~'
    };

    const int MaxLength = 8;

    static void BuildWord(int currentLength, int desiredLength, char[] word)
    {
      if (currentLength == desiredLength)
      {
        Console.WriteLine(word);
      }
      else
      {
        for (int value = 0; value < Symbols.Length; ++value)
        {
          word[currentLength] = Symbols[value];
          BuildWord(currentLength + 1, desiredLength, word);
        }
      }
    }

    static void Main(String[] args)
    {
      double totalValues = (Math.Pow(Symbols.Length, MaxLength + 1) - Symbols.Length)/(Symbols.Length - 1);
      Console.WriteLine("Warning! You are about to print: {0} values", totalValues);
      Console.WriteLine("Press any key to continue...");
      Console.ReadKey(true /* intercept */);

      for (int desiredLength = 1; desiredLength <= MaxLength; ++desiredLength)
      {
        BuildWord(0 /* currentLength */, desiredLength, new char[MaxLength]);
      }
    }

  }
}

To be completely honest, this can be optimized further. Because it builds all the "words" of length 1, then does that work a second time in building the words of length 2. It would be smarter to build the words of length MaxLength, then truncate one letter to build a word of MaxLength-1.

Here is the optimized version... note that it does NOT return the words in the order originally requested.


, '%', '^', '&', 
      '*', '(', ')', '-', '_', '+', '=', '/', '\\', '[', ']', '{', '}', ';', ':', '\'', '"', 
      ',', '.', '<', '>', '?', '`', '~'
    };

    const int MaxLength = 8;

    static void BuildWord(int currentLength, int desiredLength, char[] word)
    {
      if (currentLength != desiredLength)
      {
        for (int value = 0; value < Symbols.Length; ++value)
        {
          word[currentLength] = Symbols[value];
          BuildWord(currentLength + 1, desiredLength, word);
        }
        word[currentLength] = '\0';
      }

      Console.WriteLine(word);
    }

    static void Main(String[] args)
    {
      double totalValues = (Math.Pow(Symbols.Length, MaxLength + 1) - Symbols.Length)/(Symbols.Length - 1);
      char[] word = new char[MaxLength];

      Console.WriteLine("Warning! You are about to print: {0} values", totalValues);
      Console.WriteLine("Press any key to continue...");
      Console.ReadKey(true /* intercept */);

      BuildWord(0 /* currentLength */, MaxLength, new char[MaxLength]);
    }

  }
}
, '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', '/', '\\', '[', ']', '{', '}', ';', ':', '\'', '"', ',', '.', '<', '>', '?', '`', '~' }; const int MaxLength = 8; static void BuildWord(int currentLength, int desiredLength, char[] word) { if (currentLength == desiredLength) { Console.WriteLine(word); } else { for (int value = 0; value < Symbols.Length; ++value) { word[currentLength] = Symbols[value]; BuildWord(currentLength + 1, desiredLength, word); } } } static void Main(String[] args) { double totalValues = (Math.Pow(Symbols.Length, MaxLength + 1) - Symbols.Length)/(Symbols.Length - 1); Console.WriteLine("Warning! You are about to print: {0} values", totalValues); Console.WriteLine("Press any key to continue..."); Console.ReadKey(true /* intercept */); for (int desiredLength = 1; desiredLength <= MaxLength; ++desiredLength) { BuildWord(0 /* currentLength */, desiredLength, new char[MaxLength]); } } } }

To be completely honest, this can be optimized further. Because it builds all the "words" of length 1, then does that work a second time in building the words of length 2. It would be smarter to build the words of length MaxLength, then truncate one letter to build a word of MaxLength-1.

Here is the optimized version... note that it does NOT return the words in the order originally requested.

女皇必胜 2024-08-17 10:57:23

要使用 Java 示例来完成这篇文章,该示例将仅使用 0-9 和 az 字符打印出所有可能的字符组合的 Base64 编码 MD5:

MessageDigest digest = MessageDigest.getInstance("MD5");
int i = 0;
while (true)
{
    String raw = Integer.toString(i, Character.MAX_RADIX);
    byte[] md5 = digest.digest(raw.getBytes());
    String base64 = new BigInteger(1, md5).toString(16);
    System.out.println(raw + " = " + base64);
    i++;
}

To complete the post with a Java example which will print out the Base64 encoded MD5's of all possible character combinations using only 0-9 and a-z characters:

MessageDigest digest = MessageDigest.getInstance("MD5");
int i = 0;
while (true)
{
    String raw = Integer.toString(i, Character.MAX_RADIX);
    byte[] md5 = digest.digest(raw.getBytes());
    String base64 = new BigInteger(1, md5).toString(16);
    System.out.println(raw + " = " + base64);
    i++;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文