I would like to know how I could return every output of the list crack into a Text file
For example if I get:
abandon able ability
I would to have this (what I call output of crack) output in a text file. And so on
def generate(arr, i, s, len):
# base case
if (i == 0): # when len has
# been reached
# print it out
print(s)
return
# iterate through the array
for j in range(0, len):
# Create new string with
# next character Call
# generate again until
# string has reached its len
appended = s arr[j]
generate(arr, i - 1, appended, len)
return
# function to generate
# all possible passwords
def crack(arr, len):
# call for all required lengths
for i in range(3 , 5):
generate(arr, i, "", len)
# Driver Code
arr = ["abandon ","ability ","able ","about ","above ","absent "]
len = len(arr)
crack(arr, len)
CodePudding user response:
Demonstration of permutation vs combination of 3 items taken from a group of 5 items
In math the words combination and permutation have specific and different meanings. for 2048 items taken 12 at a time:
permutation
means the order of the 12 items is significant and the results will be5.271537971E 39
items.combination
means the order of the 12 items is not significant and the results will be '1.100526171E 31' items.- Both combination and permutation are easy to program in python using the `itertools' library. But, either program will take a long time to run.
import itertools
lower_case_letters = ['a', 'b', 'c', 'd', 'e']
print(' Permutations '.center(80, '*'))
permutations = []
sample_size = 3
for unique_sample in itertools.permutations(lower_case_letters, sample_size):
permutations.append(unique_sample)
print(f'{len(permutations)=} {unique_sample=}')
f = open('permutations_results.txt', 'w')
for permutation in permutations:
f.write(", ".join(permutation) '\n')
f.close()
print(' Combinations '.center(80, '*'))
combinations = []
for unique_sample in itertools.combinations(lower_case_letters, sample_size):
combinations.append(unique_sample)
print(f'{len(combinations)=} {unique_sample=}')
f = open('combinations_results.txt', 'w')
for combination in combinations:
f.write(", ".join(combination) '\n')
f.close()