Search code examples
pythonscriptingpycharmpython-3.8

Adding the numbers 00-99 on each txt document entry


I am building a list from scratch. I got a list offline and removed unwanted characters. Now I need to add every two digit possibility 00-99. I am doing this as I am learning how to password crack for a pen-testing competition. The exact thing I am trying to do is found on this website. https://galvanizedsecurity.wordpress.com/2016/03/16/cracking-passwords/

I am a very new to python and have only done some beginner tutorials.

This is the code I used:

lines = [line.rstrip('\n') for line in open('SVU2.txt')]
print lines num= len(lines)
for names in lines:
     for x in range(100):
         print names.lower()+%02d%x

The IDE I am using is PyCharm and I am getting syntax errors at: print lines num= len(lines) Also print names.lower() Also +%02d%x

I thought the print syntax is supposed to be 'print(lines num= len(lines))' this doesn't seem to clear the errors and I don't fully understand the code.

The author also says this is a script, am I supposed to do it a different way? Such as, not put it in the IDE?

Any help would be beneficial and I thank you seasoned and substantially smarter people than myself.


Solution

  • Use format to print variable values concatenated with strings. Also, the link you're referring to is using python 2.x whereas you're using python 3.x.

    lines = [line.rstrip('\n') for line in open('SVU2.txt')]
    print('lines num={}'.format(len(lines)))
    for names in lines:
         for x in range(100):
             print(names.lower()+"{0:0=2d}".format(x))