python - 剪刀石头布 HMAC(SHA-3 或 SHA-2)加密
问题描述
我有一个游戏(石头剪刀布)。如何使用 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')
解决方案
推荐阅读
- angular - 使用点击事件Angular 8一次打开一个键值
- javascript - 如何将函数返回的值获取到 React 中的另一个类中
- java - 如何从 Dailymotion 的 URL 获取视频下载大小
- typescript - 选择哪种 OOP 方法?
- autodesk-forge - 是否有可能获得 Revit 套件?
- mysql - 插入中的 MySQL SELECT
- javascript - 延迟加载模块的角度 onSameUrlNavigation
- cors - 在服务器上调用 axios,但在页面上调用 axios,而不是在启动时获取或异步数据
- android - 如何为图标启动器设置不同形状的图标?
- asp.net-core - 帐户锁定时间跨度溢出