Apologies if this is an incredibly simple question...I'm completely new to Python and am learning as I go.
An old post (Find all combinations (upper and lower and symbols) of a word in python) shows a way to provide multiple permutations of a input word into leet-speak (Thank you Moose!). The code works beautifully, but the code presented only allows one input word; in this case: Password.
I want to use a text file, with one word per line, as input into the code snippet shown in the link above and save the results into a new text file.
I would have thought it rather straightforward: open input file as read only, open output file for writing, substitute the value of infile.readlines() into the def and write result to the outfile. Rinse and repeat. Yet, despite trying a few different approaches and syntax, I can't get this to work.
My botched attempt to modify moose's code looks like this:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from itertools import product
def getAllCombinations(password):
leet = ["Aa@","Bb","Cc", "Dd","Ee","Ff","Gg","Hh","Ii","Jj","Kk",
"Ll","Mm","Nn","Oo0","Pp","Qq","Rr","Ss5","Tt","Uu","Vv",
"Ww","Xx","Yy","Zz"]
getPlaces = lambda password: [leet[ord(el.upper()) - 65] for el in password]
for letters in product(*getPlaces(password)):
yield "".join(letters)
with open("wordlist_in.txt", "r") as infile, open("wordlist_out.txt", "w") as outfile:
data = infile.readlines()
for el in getAllCombinations(data): <<<Pretty sure this is where I go wrong
outfile.write(el+'\n')
How do I get the string contained in each line of the file to be the input for getAllCombinations?
Thank you in advance for your help!