#๐ Making a SHA 256 encrypted code but it doesnt really work.. I keep getting an error
12 messages ยท Page 1 of 1 (latest)
@near wave
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
import hashlib
choices = ["rock", "paper", "scissors"]
while True:
player1_choice = input("Player 1, enter your choice: ")
player1_hash = hashlib.sha256(player1_choice.encode('utf-8')).hexdigest()
print("Player 1 hash:", player1_hash)
player2_choice = input("Player 2, select rock, paper or scissors: ")
print("Player 1, enter your unhashed key:")
player1_answer = input()
player1_words = player1_answer.split()
for word in player1_words:
if word in choices:
player1_choice = word
break
if player1_choice not in choices:
print("Invalid unhashed key!")
continue
if hashlib.sha256(player1_choice.encode('utf-8')).hexdigest() != player1_hash:
print("Error: Hashes do not match!")
continue
print(f"\nPlayer 1 chose {player1_choice}, Player 2 chose {player2_choice}")
if player1_choice == player2_choice:
print("It's a tie!")
elif player1_choice == "rock":
elif player1_choice == "paper":
elif player1_choice == "scissors":
play_again = input("\nPlay again? (y/n) ")
if play_again.lower() != 'y':
break
File "C:\Users\omgpr\PycharmProjects\helloworld\sha256rps#.py", line 44
elif player1_choice == "paper":
^
IndentationError: expected an indented block after 'elif' statement on line 41
im unsure on what to fix
if anyone has any other working code that does the exact same thing im trying to do, please do post
well i fixed the elif issue but it keeps saying the hashes do not match
choices = ["rock", "paper", "scissors"]
while True:
# Player 1 hash
player1_choice = input("Player 1, enter your choice: ")
player1_hash = hashlib.sha256(player1_choice.encode('utf-8')).hexdigest()
print("Player 1 hash:", player1_hash)
# Player 2 choice
player2_choice = input("Player 2, select rock, paper or scissors: ")
# Player 1 key
print("Player 1, enter your unhashed key:")
player1_answer = input()
# Extract choice
player1_words = player1_answer.split()
for word in player1_words:
if word in choices:
player1_choice = word
break
# Validate key
if player1_choice not in choices:
print("Invalid unhashed key!")
continue
# Verify hashes
if hashlib.sha256(player1_choice.encode('utf-8')).hexdigest() != player1_hash:
print("Error: Hashes do not match!")
continue
# Game logic
print(f"\nPlayer 1 chose {player1_choice}, Player 2 chose {player2_choice}")
if player1_choice == player2_choice:
print("It's a tie!")
elif player1_choice == "rock":
print("Rock logic")
elif player1_choice == "paper":
print("Paper logic")
elif player1_choice == "scissors":
print("Scissors logic")
# Play again
play_again = input("\nPlay again? (y/n) ")
if play_again.lower() != 'y':
break
So whats the error?
it seems to work?
at least I don't get any "hashes do not match" unless I intentionally put in the wrong one for the second player1 input
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.