单词的组合…功率集

Combinations of Words...Power Set?

本文关键字:功率 组合 单词      更新时间:2023-10-16

我想破解一个我忘记的密码。我知道密码中可能使用的所有单词,但有些可能使用或不使用。例如:HarryMetSally可能是密码,但我可能会使用"Harry"Billy"Sally"answers"Met"的单词列表来组合破解。

如果我有16个单词,但可能使用了14-16个单词,我如何在c++或Python中编写16个单词(或20,25,30个单词)随机连接在一起并一次使用1个或2-16个单词,甚至不以相同的顺序使用。

的例子:

文字:Harry Billy Sally Met

结合例子:

哈利比利SallyBillyBillySallyHarryMetSallyHarrySallyMet

我在网上广泛搜索,也尝试过Excel论坛。指导吗?

你说随机…

#include <iostream>
#include "stdlib.h"
#include "time.h"
#define NUM_WORDS 3
char* words[NUM_WORDS] = {
    "Foo",
    "Bar",
    "Baz"
};
typedef unsigned long long ULL;
ULL fact(ULL n, ULL lowerLimit = 1)
{
    if (n <= lowerLimit) return 1;
    return n * fact(n - 1);
}
int main()
{
    srand(time(NULL));
    // I can try single words all by myself, so start at 2 or more words
    for (int nWords = 2; nWords <= NUM_WORDS; ++nWords)
    {
        // calculate the number of possibilities
        // but since it's random, triple it for good measure
        ULL nIters = fact(NUM_WORDS, NUM_WORDS - nWords) * 3;
        for (ULL iter = 0; iter < nIters; ++iter)
        {
            for (int iterWord = 0; iterWord < nWords; ++iterWord)
            {
                int ix = rand() % NUM_WORDS;
                std::cout << words[ix];
            }
            std::cout << std::endl;
        }
    }
    return 0;
}