Skip to content
Snippets Groups Projects
Commit b0224952 authored by David Palmer's avatar David Palmer
Browse files

Upload New File

parent dcb32005
Branches
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment