Hey guys...

I created a uber-basic brute force program(not exactly 'brute force'), where in the program opens a 'log.txt' file and reads the contents. I created a list of alphabets A-Z and numbers 0-9....what I wanted the program to do was, try out different combinations with the given set of characters until it matches the given set of characters in the log.txt file, and then display an appropriate message...here's the code I used:

killzone2(in the log.txt file)

``````import random

combos=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','v','w','x','y','z']
combos.append(range(10))
choice=random.choice(combos)

log=open('log.txt','r')
choice=random.choice(combos)
print choice``````

Thanks for the help in advance all you guys! ;P

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by vegaseat

When comparing two strings you want to make sure they are the same length. They will never be equal if they are different lengths, so add a statement which prints if they are not equal,

``````log_fp=open('log.txt','r')
print "choice length", choice, len(choice), \
choice=random.choice(combos)
print choice``````

When comparing two strings you want to make sure they are the same length. They will never be equal if they are different lengths, so add a statement which prints if they are not equal,

``````log_fp=open('log.txt','r')
print "choice length", choice, len(choice), \
choice=random.choice(combos)
print choice``````

Hey, I got to know one more thing(I think I'm correct) that the 'choice' command only picks a *single* entity from the list....so since my actual text is 'killzone2', the program will go on for ever and never end, because every time, only a single character will be matched with the given text! :( Any idea on how to actually pick items randomly from a list? Thnks

Even if you use the modified code below, it will take almost forever ...

``````import random
import string

combos = list(string.ascii_lowercase + string.digits)

#log=open('log.txt','r')
# for test only
search = 'killzone2'
combo = ''
while combo != search:
# build up string combo the same length as search
for n in search:
combo += random.choice(combos)
# test
print combo,
# reset
combo = ''

print combo``````