[Tutor] bruteforce match word in text file
david at abbottdavid.com
Thu Jan 22 01:01:36 CET 2009
bob gailer wrote:
> David wrote:
>> bob gailer wrote:
>>> David wrote:
>>>> I have to ask for a pointer, not sure what I am doing wrong.
>>> The first thing you are doing "wrong" is failing to tell us what is
>>> in the wordlist file and what results you get when you run the program.
>>> Please re-post with that information.
>>>> password = 'loser'
>>>> wordlist = '/home/david/Challenge-You/wordlist.txt'
>>>> words = open(wordlist, 'r').readlines()
>>>> except IOError, e:
>>>> print "Sorry no words"
>>>> for word in words:
>>>> word = word.replace("\n","")
>>>> if password in word:
>>>> print word
>>>> print 'You are a loser'
> Now what can you change to get it to do what (I assume) you want -
> examine each "word" in the file, print the word if 'loser' is in it, and
> print 'You are a loser' ONLY if no words match.
I changed the wordlist.txt to
and the program;
password = 'loser'
wordlist = '/home/david/Challenge-You/wordlist.txt'
words = open(wordlist, 'r').readlines()
except IOError, e:
print "Sorry no words"
for word in words:
word = word.replace("\n","")
if password in word:
print "The password is: ", word
I could not figure out how to split the file into words.
Powered by Gentoo GNU/LINUX
More information about the Tutor