-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.py
More file actions
64 lines (50 loc) · 2.18 KB
/
Copy pathvalidate.py
File metadata and controls
64 lines (50 loc) · 2.18 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def word_on_card(word_index, card_number):
patterns = {
0: {1: True, 2: True, 3: False},
1: {1: False, 2: True, 3: True},
2: {1: True, 2: False, 3: True},
}
pattern_index = word_index % 3
return patterns[pattern_index][card_number]
def validate_recovery():
print("Validating 2-of-3 card recovery for 24 words...")
print("Pattern: Word 1: 1-yes, 2-yes, 3-no - Word 2: 1-no, 2-yes, 3-yes - Word 3: 1-yes, 2-no, 3-yes")
print()
# Check all possible 2-card combinations
card_combinations = [(1, 2), (1, 3), (2, 3)]
all_valid = True
for combo in card_combinations:
print(f"Testing cards {combo[0]} + {combo[1]}:")
missing_words = []
for word_pos in range(24): # 24 words in BIP39
# Check if word appears on at least one of the two cards
appears_on_card1 = word_on_card(word_pos, combo[0])
appears_on_card2 = word_on_card(word_pos, combo[1])
if not (appears_on_card1 or appears_on_card2):
missing_words.append(word_pos + 1)
if missing_words:
print(f" ❌ FAILED: Words {missing_words} are missing from both cards")
all_valid = False
else:
print(" ✅ PASSED: All words recoverable")
print()
# Detailed analysis
print("Detailed word coverage analysis:")
print("Word# Card1 Card2 Card3 | 1+2 1+3 2+3")
print("-------|-------|-------|-------|-----|-----|-----")
for word_pos in range(24):
c1 = word_on_card(word_pos, 1)
c2 = word_on_card(word_pos, 2)
c3 = word_on_card(word_pos, 3)
combo_12 = c1 or c2
combo_13 = c1 or c3
combo_23 = c2 or c3
print(f"Word{word_pos+1:2d} {c1!s:5} {c2!s:5} {c3!s:5} | {combo_12!s:3} {combo_13!s:3} {combo_23!s:3}")
print()
if all_valid:
print("🎉 VALIDATION SUCCESSFUL: All word combinations can be recovered with any 2 of 3 cards!")
else:
print("💥 VALIDATION FAILED: Some words cannot be recovered with 2 cards!")
return all_valid
if __name__ == "__main__":
validate_recovery()