Skip to content

Commit

Permalink
Prints out the flag after winning the game (#26)
Browse files Browse the repository at this point in the history
* Prints out the flag after winning the game

* Changed to try-finally block to print out the flag when player wins the game

* naming convention changes
  • Loading branch information
ChefToan authored Nov 18, 2024
1 parent 4eb05c3 commit dd7c436
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions reverse-engineering/cimg-quest-1/_0/quest.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def game():
flag = b"ERROR: /flag permission denied"

hidden_bytes = [ bytes([b]) for b in flag ][::-1]

hidden_x = random.randrange(w)
hidden_y = random.randrange(h)
revealed_bytes = [ ]
Expand Down Expand Up @@ -192,21 +193,27 @@ def game():

# render everyone
screen.blank()
correct_bytes = ''
for rx,ry,r,g,b,c in revealed_bytes:
screen.render_patch_monochrome([ c ], rx, ry, r=r, g=g, b=b)
screen.render_patch_monochrome([c], rx, ry, r=r, g=g, b=b)
correct_bytes += str(c.decode())
if hidden_bytes:
screen.render_patch_monochrome(
[ b"?" ], hidden_x, hidden_y,
[b"?"], hidden_x, hidden_y,
r=random.randrange(256), g=random.randrange(256), b=random.randrange(256)
)
else:
while True:
screen.animate_text("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", 10, hidden_y)
screen.animate_text("!!! CONGRATULATIONS, YOU DID IT !!!", 10, hidden_y+1)
screen.animate_text("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", 10, hidden_y+2)
screen.animate_text("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", 10, hidden_y+1)

screen.render_patch_monochrome([ b"B" ], bomb_x, bomb_y)
try:
while True:
screen.animate_text("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", 10, hidden_y)
screen.animate_text("!!! CONGRATULATIONS, YOU DID IT !!!", 10, hidden_y + 1)
screen.animate_text(correct_bytes, 10, hidden_y + 2)
screen.animate_text("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", 10, hidden_y + 1)
except KeyboardInterrupt:
print(flag.decode(), file=sys.stderr) # Print decoded flag to stderr
break

screen.render_patch_monochrome([b"B"], bomb_x, bomb_y)
screen.render_sprite(our_sprite, x, y)
screen.flush()

Expand Down

0 comments on commit dd7c436

Please sign in to comment.