-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbob.py
More file actions
38 lines (38 loc) · 1.21 KB
/
bob.py
File metadata and controls
38 lines (38 loc) · 1.21 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
import hashlib
import socket
clientSocket = socket.socket()
serverIP = raw_input("enter alices's ip address to connect ")
port = input("enter port no ")
clientSocket.connect((serverIP,port))
print("connected successfully ")
aliceCommitment = clientSocket.recv(102400)
print("alice has commited ")
print(aliceCommitment)
bobChoice = raw_input("enter either rock, paper or scissor ")
clientSocket.send(bobChoice)
aliceSecret = clientSocket.recv(102400)
aliceChoice = clientSocket.recv(102400)
if(hashlib.sha256(aliceSecret+aliceChoice).hexdigest() == aliceCommitment):
if bobChoice == "rock":
if aliceChoice == bobChoice :
print("draw")
elif aliceChoice == "scissor" :
print("you won")
else:
print("you lost")
elif bobChoice == "scissor":
if aliceChoice == bobChoice:
print("draw")
elif aliceChoice == "paper":
print("you won")
else:
print("you lost")
else:
if aliceChoice == bobChoice:
print("draw")
elif aliceChoice == "rock":
print("you won")
else:
print("you lost")
else:
print("alice has cheated ")