forked from Coldcard/wordlist-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-wordlist.py
71 lines (56 loc) · 2.28 KB
/
make-wordlist.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
61
62
63
64
65
66
67
68
69
70
71
from reportlab.lib import colors
from reportlab.lib.pagesizes import letter, landscape
from reportlab.lib.units import inch
from reportlab.lib.enums import *
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from mnemonic import Mnemonic
wordlist = Mnemonic('english').wordlist
styleSheet = getSampleStyleSheet()
labelStyle = ParagraphStyle('llab', fontFace='courier', alignment=TA_RIGHT)
labelStyleCenter = ParagraphStyle('tlab', fontFace='courier', alignment=TA_CENTER)
hex_style = ParagraphStyle('tlab', fontName='Courier-Bold', alignment=TA_LEFT, fontSize=6, spaceAfter=2, spaceBefore=0, leading=4)
word_style = ParagraphStyle('cell', alignment=TA_CENTER, fontSize=8, spaceBefore=0, spaceAfter=0, leading=8)
def cell(w):
assert 0 <= w < 0x800
word = wordlist[w]
hex = ('%03x' % w).upper()
#rv = Paragraph(f'{word}\n<br/><font face="courier">{hex}</font>', cellStyle)
rv = []
rv.append(Paragraph(hex, hex_style))
rv.append(Paragraph(word, word_style))
return rv
def left_label(x):
return Paragraph(x, labelStyle)
def top_label(x):
return Paragraph(x, labelStyleCenter)
def doit(fname='wordlist.pdf'):
doc = SimpleDocTemplate(fname, pagesize=landscape(letter))
doc.leftMargin = doc.rightMargin = \
doc.topMargin = doc.bottomMargin = 0.1 * inch
# container for the 'Flowable' objects
elements = []
rowlen = 16
#data = [[''] + [ top_label('+%d' % i) for i in range(rowlen)]]
#[left_label('0x%03x'%j)] +
data = [
[cell(j+i) for i in range(0, rowlen)]
for j in range(0, 0x800, rowlen) ]
t = Table(data, repeatRows=0)
t.setStyle(TableStyle([
#('BACKGROUND',(1,1),(-2,-2),colors.green),
#('TEXTCOLOR',(0,0),(0,-1),colors.red),
#('VALIGN', (0,0),(0,-1), 'MIDDLE'),
#('ALIGN', (0,0),(0,-1), 'RIGHT'),
#('ALIGN', (0,0),(-1,0), 'CENTER'),
('LEFTPADDING', (0,0),(-1,-1), 2),
('RIGHTPADDING', (0,0),(-1,-1), 2),
('TOPPADDING', (0,0),(-1,-1), 0),
('BOTTOMPADDING', (0,0),(-1,-1), 4.25),
('GRID', (0,0),(-1,-1), 0.5, colors.grey),
]),
)
elements.append(t)
# write the document to disk
doc.build(elements)
doit()