Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GroupProject
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joe Stephenson
GroupProject
Commits
e4825c67
Commit
e4825c67
authored
Oct 16, 2024
by
Joe Stephenson
Browse files
Options
Downloads
Patches
Plain Diff
Added comments and TODOs to decoder puzzle
parent
e6d688e2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
decoder.py
+20
-5
20 additions, 5 deletions
decoder.py
with
20 additions
and
5 deletions
decoder.py
+
20
−
5
View file @
e4825c67
...
...
@@ -2,9 +2,6 @@ import random
password
=
"
undecoded
"
# these 2 functions are far too bulky, break them down into smaller functions
# could nest functions maybe? Not sure if that is good practice or not
def
function_guessing
():
function
=
functionSetter
()
printInfo
(
function
)
...
...
@@ -24,13 +21,17 @@ def function_guessing():
def
decode
():
# Allows for 2 attemps in case the user mistypes
for
j
in
range
(
2
):
guess
=
input
(
"
Guess the password:
"
)
# TODO Remove this
if
guess
==
""
:
quit
()
if
guess
==
password
:
print
(
"
CORRECT
"
)
break
# Needs to make sure the user knows they have one more try or if they have just failed
else
:
if
j
==
0
:
print
(
"
One more try!
"
)
...
...
@@ -39,6 +40,9 @@ def decode():
def
functionSetter
():
'''
Returns the randomly generated number to act as the function
'''
# Needed to have 2 seperate random number generators for negative and positive numbers as it is not continuous
# And also needed to randomly choose if the function is negative or positive
negpos
=
random
.
randint
(
0
,
1
)
if
negpos
:
return
random
.
randint
(
3
,
23
)
...
...
@@ -47,18 +51,24 @@ def functionSetter():
def
encode
(
function
):
'''
Returns a string that seems like a jumble of random letter
'''
# Creating a list with the corresponding place in the alphabet of each letter in the word
nums_of_chars
=
[]
for
char
in
password
:
num
=
ord
(
char
)
-
96
nums_of_chars
.
append
(
num
)
# Creates a list, where each item is a letter in the now encoded word
encoded_list
=
[]
for
item
in
nums_of_chars
:
# This ensures that when going above 26, it goes back to 1 again
# TODO Make sure this can also work when going into negative numbers
num
=
(
item
+
function
)
%
26
if
num
==
0
:
num
=
26
encoded_list
.
append
(
chr
(
num
+
96
))
# converts the list of the encoded word to a string
encoded
=
""
for
item
in
encoded_list
:
encoded
+=
item
...
...
@@ -67,12 +77,18 @@ def encode(function):
def
printInfo
(
function
):
# Maybe like actually use this function
'''
Information is printed, the word is also encoded here as each time the user fails to decode the word
it will change and be printed here
'''
print
(
"
Figure out the function to decode the password
"
)
encoded_word
=
encode
(
function
)
print
(
"
This is the encoded password:
"
,
encoded_word
)
def
decoder_puzzle
():
'''
Runs the decoding loop, currently allowing for an infinite amount of trys to guess the function
'''
correct
=
False
while
not
correct
:
correct
=
function_guessing
()
...
...
@@ -80,4 +96,3 @@ def decoder_puzzle():
decode
()
#decoder_puzzle()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment