Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit bb5b772

Browse files
authored
Merge pull request #6 from avipars/python-code-format-patches
Fixes by format action
2 parents 9ecd814 + fd1ad5f commit bb5b772

File tree

3 files changed

+46
-35
lines changed

3 files changed

+46
-35
lines changed

flags.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"Blind in one eye, deaf in the other.",
66
"Zoom in, zoom out, and you'll find what you seek.",
77
"You have the audacity to ask for another hint, so soon?",
8-
"Spectre", #spectrogram
9-
"Linearity is a myth.", #linear in spectrogram
8+
"Spectre", # spectrogram
9+
"Linearity is a myth.", # linear in spectrogram
1010
"Look in the mirror, that's your competition.",
1111
],
1212
"notes": "It doesn't get easier, you just get better.",
@@ -27,9 +27,8 @@
2727
"hints": [
2828
"This might be a site for sore eyes.",
2929
"If the past could be changed, it would not exist.",
30-
"We go way back"
31-
"Secrets often lie where robots tell you not to look.",
32-
"Every locked door has a key. Every problem has a solution."
30+
"We go way back" "Secrets often lie where robots tell you not to look.",
31+
"Every locked door has a key. Every problem has a solution.",
3332
],
3433
"notes": "If the final site is not loading, refresh and wait... (or try to add alt. to the URL)",
3534
},
@@ -40,7 +39,7 @@
4039
"You cannot reach the right destination by walking on the wrong path",
4140
"A path is a prior interpretation of the best way to traverse a landscape.",
4241
"One new notification",
43-
"One man's trash is another man's treasure.", # recycle bin
42+
"One man's trash is another man's treasure.", # recycle bin
4443
"Reduce, Reuse, Recycle",
4544
],
4645
"notes": "Some flags can unlock more than one door.",
@@ -64,5 +63,5 @@
6463
"Check all the windows.",
6564
],
6665
"notes": "Nearly there!",
67-
}
68-
}
66+
},
67+
}

hints/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# import based on your project structure
44

5+
56
def create_app():
67
print("Creating app")
78
app = Flask(
@@ -28,5 +29,6 @@ def create_app():
2829
# app.config['referrer_policy'] = 'strict-origin-when-cross-origin'
2930
return app
3031

32+
3133
# app.config['referrer_policy'] = 'strict-origin-when-cross-origin'
3234
from hints import routes # nopep8

hints/routes.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
import uuid
3+
34
from flask import (Blueprint, flash, redirect, render_template, request,
45
session, url_for)
56
from markupsafe import escape
@@ -25,7 +26,7 @@ def flags():
2526
session["hint_index"] = 0
2627
if "token" not in session:
2728
session["token"] = str(uuid.uuid4()) # generate a random token
28-
29+
2930
current_stage = session["current_stage"]
3031
submitted_flags = session["submitted_flags"]
3132
hint_index = session["hint_index"]
@@ -37,26 +38,25 @@ def flags():
3738
if "submit_flag" in request.form:
3839
submitted_flag = request.form.get("flag")
3940
submitted_flag = escape(submitted_flag.strip())
40-
if not submitted_flag.isascii(): # make sure its ascii only and not invalid
41+
if not submitted_flag.isascii(): # make sure its ascii only and not invalid
4142
flash("Invalid flag. Please try again.", "danger")
4243
return redirect(url_for("ctf.flags"))
4344

44-
4545
if submitted_flag in submitted_flags:
4646
flash("You already submitted this flag.", "info")
4747
elif submitted_flag == stages[current_stage]["flag"]:
4848
flash(f"Correct flag for Stage {current_stage}!", "success")
49-
if submitted_flag not in submitted_flags: # no duplicates
49+
if submitted_flag not in submitted_flags: # no duplicates
5050
submitted_flags.append(submitted_flag)
5151
session["submitted_flags"] = submitted_flags
5252

5353
if current_stage < len(stages):
5454
current_stage += 1
5555
hint_index = 0
5656
elif current_stage == len(stages):
57-
flash( # if the user has completed all the stages, then flash a message
58-
"You have completed all the stages. Congratulations!",
59-
"success")
57+
flash( # if the user has completed all the stages, then flash a message
58+
"You have completed all the stages. Congratulations!", "success"
59+
)
6060
return render_template(
6161
"error.html",
6262
title="Congratulations!",
@@ -67,29 +67,37 @@ def flags():
6767
found = False
6868
# if the flag is for a different stage, then warn them
6969
for stage, stage_data in stages.items():
70-
if submitted_flag == stage_data["flag"]: # out of order
70+
if submitted_flag == stage_data["flag"]: # out of order
7171
flash(
72-
f"That's the flag for stage {stage}, but in the wrong order, try to go back and find the right one", "info")
73-
# current_stage = stage , i decided to not let them proceed to the next stage, but to stay in current one
72+
f"That's the flag for stage {stage}, but in the wrong order, try to go back and find the right one",
73+
"info",
74+
)
75+
# current_stage = stage , i decided to not let them
76+
# proceed to the next stage, but to stay in current one
7477
hint_index = 0
7578
found = True
7679

77-
if submitted_flag not in submitted_flags: # no duplicates
80+
if submitted_flag not in submitted_flags: # no duplicates
7881
submitted_flags.append(submitted_flag)
7982
session["submitted_flags"] = submitted_flags
8083

81-
# check if they got all the flags (even if they are out of order)
84+
# check if they got all the flags (even if they are out
85+
# of order)
8286
if sorted(submitted_flags) == sorted(
8387
[stage_data["flag"] for stage_data in stages.values()]
8488
):
8589
flash(
8690
"You have completed all the stages. Congratulations!", "success", )
87-
return render_template(
88-
"error.html", #not really an error, but a message
89-
title="Congratulations!",
90-
message="You have completed all the stages of the CTF. ",
91-
),200
92-
# if the user has completed all the stages, then flash a message
91+
return (
92+
render_template(
93+
"error.html", # not really an error, but a message
94+
title="Congratulations!",
95+
message="You have completed all the stages of the CTF. ",
96+
),
97+
200,
98+
)
99+
# if the user has completed all the stages, then
100+
# flash a message
93101
break
94102
# after going through all stages, flag isn't there
95103
if not found:
@@ -109,17 +117,19 @@ def flags():
109117
flash(
110118
"Exhausted all hints for this stage :( Try harder!", "warning")
111119
# hide the button till they get to next stage
112-
session["hint_index"] = hint_index # update the hint index
113-
hints = stages[current_stage]["hints"][:hint_index] # get the hints based on the hint index
114-
notes = stages[current_stage].get("notes") # get the notes if they exist
120+
session["hint_index"] = hint_index # update the hint index
121+
hints = stages[current_stage]["hints"][
122+
:hint_index
123+
] # get the hints based on the hint index
124+
notes = stages[current_stage].get("notes") # get the notes if they exist
115125
return render_template(
116126
"flags.html",
117127
title=f"CTFlask - Stage {current_stage}",
118128
stage=current_stage,
119-
hints=hints, # hints to display
120-
hint_index=hint_index, # current hint index
121-
submitted_flags=submitted_flags,
122-
num_hints=len(stages[current_stage]["hints"]), # total number of hints
129+
hints=hints, # hints to display
130+
hint_index=hint_index, # current hint index
131+
submitted_flags=submitted_flags,
132+
num_hints=len(stages[current_stage]["hints"]), # total number of hints
123133
notes=notes,
124134
)
125135

@@ -138,7 +148,7 @@ def index():
138148
session["hint_index"] = 0
139149
if "token" not in session:
140150
session["token"] = str(uuid.uuid4()) # generate a random token
141-
151+
142152
flash("Welcome to the CTF, please read the following:", "info")
143153
brief = """
144154
Using this site is not required to solve the CTF challenge and is not a part of the CTF challenge itself, but a tool to help you keep track of your progress. You need to find the flags on your own and not via this site itself. Good luck!
@@ -188,4 +198,4 @@ def inject_stuff():
188198
"""
189199
used for the footer to display the current year, version
190200
"""
191-
return {"year": datetime.date.today().year, "version": "1.0.0"}
201+
return {"year": datetime.date.today().year, "version": "1.0.0"}

0 commit comments

Comments
 (0)