Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 单词组合…幂集?_Python_C++_Powerset - Fatal编程技术网

Python 单词组合…幂集?

Python 单词组合…幂集?,python,c++,powerset,Python,C++,Powerset,我想破解一个我忘记的密码。我知道密码中可能使用的所有单词,但有些可能使用或不使用。示例:HarryMetSally可能是密码,但我可能会使用“Harry”、“Billy”、“Sally”和“Met”的单词列表组合来破解 如果我有16个单词,但14-16可能被使用,我如何在C++或Python中编码16个单词(或20, 25, 30个单词),随机地连接在一起,一次使用1个,或者2-16一起,不以相同的顺序。 例如: 单词:哈里·比利·萨利遇见 组合示例: 哈利 比利 萨莉贝利 巨浪 哈利梅萨利 哈

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

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

例如:

单词:哈里·比利·萨利遇见

组合示例:

哈利 比利 萨莉贝利 巨浪 哈利梅萨利 哈利萨利米特

我在互联网上搜索过很多,也尝试过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;
}
#包括
#包括“stdlib.h”
#包括“time.h”
#定义NUM_单词3
字符*字[NUM_字]={
“福”,
“酒吧”,
“巴兹”
};
typedef无符号长ULL;
ULL事实(ULL n,ULL lowerLimit=1)
{

如果(n当然!如果您使用Python,您可能能够在同一模块中使用或使用其他函数。如果您查看文档底部,他们有一个示例说明如何使用它计算幂集。这似乎是大量可能的排列……这是一个练习还是一个实用性问题?如果您真的忘记了你的密码,我怀疑你的第一个想法是写一个python脚本来暴力破解它。感谢你的反馈。我已经在一个rar文件中锁定了35000张专业照片。我知道我用来保护它的单词。我可以对rar文件运行一个单词列表来解锁它非常重要。谢谢!你真聪明:)它在C++在线编译器上运行良好。