-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypto_deck.py
60 lines (50 loc) · 1.93 KB
/
crypto_deck.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# coding=utf-8
from cardlib.Card import Card
class CryptoCard:
"""This class encapsulates the details of a card encrypted with the Secure
Shuffle protocol. We keep a log of the cards state for debugging and a list
of all players whose locks are currently applied to the card."""
ENCRYPTED = 'encrypted'
DECRYPTED = 'decrypted'
GENERATED = 'generated'
ACTION = 'action'
LOCKS_REMOVED = 'locks_removed'
LOCKS_PRESENT = 'locks_present'
VALUE = 'value'
SHOWDOWN_DECRYPT = 'showdown_decrypt'
def __init__(self):
self.state_log = []
self.value = None
self.locks_present = []
# dealt_to identifies the player/position intended for this card
# Either a positive number => the players roll
# or a negative number => the order in which they'll be revealed
# to the table
self.dealt_to = None
self.has_been_dealt = False
self.deck_index = None
def update_state(self, action, value):
self.state_log.append({self.ACTION: action,
self.LOCKS_PRESENT: self.locks_present.copy(),
self.VALUE: value})
self.value = value
def removed_lock(self, by, new_value):
self.locks_present.remove(by)
self.update_state(self.DECRYPTED, new_value)
def generate_card(self, encrypted_by, value, deck_index):
self.deck_index = deck_index
self.locks_present = encrypted_by.copy()
self.update_state(self.GENERATED, value)
def showdown_decrypt(self, value):
self.locks_present.clear()
self.update_state(self.SHOWDOWN_DECRYPT, value)
def get_card(self):
if not self.locks_present:
return Card(self.value)
else:
print("Not fully decrypted!")
return None
class CryptoWords:
SHARE_PRIVATE = 'share_private'
SRA_KEY = 'sra_key'
PRIVATE_COMPONENT = 'private_component'