首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >具有所有组合的紧缩字列表生成

具有所有组合的紧缩字列表生成
EN

Unix & Linux用户
提问于 2018-04-19 06:36:23
回答 1查看 1.6K关注 0票数 1

我正试图生成一个单词列表,以便使用它来野蛮地使用我自己的Truecrypt容器。我确实知道密码的一部分,它是使用其他已知密码块来增加长度的,但我忘记了使用这些块的顺序,以及如果没有使用一些块的话。

用空格分隔的“块”示例:dog cat bird xyz cow1 lion8

我想要做的是创建一个包含这些块的每个可能组合的单词列表。E.g

代码语言:javascript
运行
复制
dog
cat
dogcat
catdog
bird
dogbird
catbird
birdcat
birddog
dogcatbird
catdogbird
xyz
dogcatbirdxyz
cow1
xyzcow1dogcat
xyzcow1dogcatbird
catdogbirdxyzcow8
lion8
catdogbirdxyzcow1lion8
lion8catdogbirdxyzcow1
dogcatbirdxyzcow1lion8
cow1birddogcatxyzlion8
cow1lion8birddogcatxyz
...

到目前为止,我已经尝试使用一个叫做crunch的工具:http://www.irongeek.com/i.php?page=backtrack-r1-man-pages/crunch

但挑战似乎是如何生成较短的组合,而不包括所有已知的块,例如:dogcat只包含2个块。

也许有人比我更了解crunch,或者我是否应该使用其他工具或组合工具?

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2018-04-19 06:58:49

Python

代码语言:javascript
运行
复制
#! /usr/bin/env python3
import sys
from itertools import chain, permutations
# from the docs https://docs.python.org/3/library/itertools.html#itertools-recipes
# modified for permutations instead of combinations


def powerset_perm(iterable):
    s = list(iterable)
    return chain.from_iterable(permutations(s, r) for r in range(1, len(s) + 1))


for w in powerset_perm(sys.argv[1:]):
    print("".join(w))

示例:

代码语言:javascript
运行
复制
~ ./foo.py foo フー bar1™
foo
フー
bar1™
fooフー
foobar1™
フーfoo
フーbar1™
bar1™foo
bar1™フー
fooフーbar1™
foobar1™フー
フーfoobar1™
フーbar1™foo
bar1™fooフー
bar1™フーfoo
票数 3
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/438655

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档