PW Crack 3

image_1

image_2

picoCTF{m45h_fl1ng1ng_6f98a49f}


PW Crack 4

image_3

Slightly modify the program. At first, it looks like this:

level4.py:

image_4

After changes:

level4_modified.py:

image_5

picoCTF{fl45h_5pr1ng1ng_cf341ff1}


PW Crack 5

image_6

Now we need to substitute values from the dictionary:

level5.py:

image_7

image_8

This task can be solved in 2 ways:

# method 1
with open('dictionary.txt', 'r') as f:
    lines = f.readlines() 
    lines_amount = len(lines) 
    i = 0
    for i in range(lines_amount):
        var = lines[i].strip()
        flag = level_5_pw_check(var)
    print(flag)
# method 2
with open('dictionary.txt', 'r') as f: 
    for line in f:
        var = line.strip()
        flag = level_5_pw_check(var)
    print(flag)

The main difference between these two options is that in 1:

  • f.readlines() usually called in the block with open only once, the file pointer (cursor) moves to the end of the file, and when this method is called again, the pointer, which is already at the end, simply returns an empty list
  • However, to reuse it, you need to use the f.seek() method to move the cursor back.

First call f.readlines(): Reads all lines, cursor at the end.

Second call f.readlines() (and next calls): The cursor is already at the end, so there are no “remaining lines” from the current position. Method simply returns an empty list ([]).

The second method is more Pythonic, because the object as f: is itself an iterator over strings.

image_10

picoCTF{h45h_sl1ng1ng_36e992a6}