石头剪子HMAC(SHA3或SHA2)加密

2024-05-23 18:26:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个游戏(石头、布、剪刀)。 如何使用HMAC(SHA-2或SHA-3)加密计算机的答案,并在游戏结束时与用户的答案进行比较?你知道吗

import random
import hmac
import hashlib
import base64

options = {"r": "rock", "p": "paper", "s": "scissors"}

while True:
    user = input('Choose r for rock, p for paper, s for scissors or q to quit: ')
    user = user.lower()

    if user == 'q':
        break
    if user not in options.keys():
        continue

    choice = random.choice(list(options.keys()))
    print('Computer picked:', options[choice])

    if choice == user:
        print('You tie against the computer\n')
    elif (user, choice) in (("r", "s"), ("p", "r"), ("s", "p")):
        print('You win against the computer\n')
    else:
        print('You lose against the computer\n')

Tags: the答案importyou游戏forifrandom