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
b0224952
Commit
b0224952
authored
Oct 22, 2024
by
David Palmer
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
dcb32005
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
+178
-0
178 additions, 0 deletions
decoder.py
with
178 additions
and
0 deletions
decoder.py
0 → 100644
+
178
−
0
View file @
b0224952
import
random
password
=
"
apuzaazle
"
def
print_key
():
print
(
1
,
""
,
2
,
""
,
3
,
""
,
4
,
""
,
5
,
""
,
6
,
""
,
7
,
""
,
8
,
""
,
9
,
""
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
,
21
,
22
,
23
,
24
,
25
,
26
,
)
print
(
"
a
"
,
"
b
"
,
"
c
"
,
"
d
"
,
"
e
"
,
"
f
"
,
"
g
"
,
"
h
"
,
"
i
"
,
"
j
"
,
"
k
"
,
"
l
"
,
"
m
"
,
"
n
"
,
"
o
"
,
"
p
"
,
"
q
"
,
"
r
"
,
"
s
"
,
"
t
"
,
"
u
"
,
"
v
"
,
"
w
"
,
"
x
"
,
"
y
"
,
"
z
"
,
)
def
function_guessing
(
encoded_word
,
function
):
print
(
"
Figure out the function to decode the password
"
)
print
(
"
This is the encoded password:
"
,
encoded_word
)
print
(
function
)
function_guess
=
0
for
i
in
range
(
5
,
0
,
-
1
):
run
=
True
while
run
:
try
:
function_guess
=
int
(
input
(
"
Guess a number between -26 and 26:
"
))
run
=
False
except
ValueError
:
print
(
"
Enter an integer between -26 and 26
"
)
if
function_guess
>
function
:
print
(
"
Lower
"
)
elif
function_guess
<
function
:
print
(
"
Higher
"
)
else
:
return
True
print
(
"
You have
"
,
i
,
"
guesses left
"
)
return
False
def
decode
(
encoded_word
):
# Allows for 2 attemps in case the user typo or mistake
for
j
in
range
(
2
):
print
(
"
The function you have found will be how many places in the alphabet is added to or subracted from the non-encoded password
"
)
print
(
"
This is the encoded password:
"
,
encoded_word
)
print_key
()
guess
=
input
(
"
Guess the password:
"
)
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!
"
)
else
:
print
(
"
FAIL
"
)
def
function_setter
():
"""
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
)
else
:
return
random
.
randint
(
-
23
,
-
3
)
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 and when going below 1 it goes to 26
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
return
encoded
def
decoder_puzzle
():
"""
Runs the decoding loop, currently allowing for an infinite amount of trys to guess the function
"""
for
c
in
range
(
2
,
-
1
,
-
1
):
function
=
function_setter
()
encoded_word
=
encode
(
function
)
# function = -(function)
correct
=
function_guessing
(
encoded_word
,
function
)
if
correct
:
print
(
"
That is the function!
"
)
break
else
:
if
c
==
0
:
print
(
"
You Failed
"
)
else
:
print
(
"
You have
"
,
c
,
"
more chances!
"
)
if
correct
:
decode
(
encoded_word
)
else
:
return
False
return
True
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