Exact probabilities of obtaining a DER encoded signature of a certain length

Python3 code:

# order of secp256k1 curve
ec_order = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141


def drop_bytes_to_int(inp, n):
    """convert the int 'inp' to bytes (32), drop the first n bytes, return the corresponding int
    """
    return int.from_bytes((inp.to_bytes(32, "big")[n:]), "big")


# Step 1: P(n-th byte strictly below 0x80)
P1 = []
for i in range(32):
    P1 += [min(1, 2 ** (8 * (32 - i) - 1) / (drop_bytes_to_int(ec_order, i) - 1))]
# Step 2: P(n-th byte equal t0 0x00)
P2 = []
for i in range(32):
    P2 += [2 ** (8 * (32 - i - 1)) / (drop_bytes_to_int(ec_order, i) - 1)]
# Step 3: P(int encoded in n or less bytes), i.e. cumulative distribution
P3 = [1]
for i in range(32):
    tot = 1
    for j in range(i):
        tot *= P2[j]
    P3 += [P1[i] * tot]
P3 += [0]
# Step 4: P(int encoded in n bytes)
P4 = []
for i in range(33):
    P4 += [P3[i] - P3[i + 1]]
# Step 5: P(signature encoded in n bytes)
P5 = []
for i in range(66):
    tot = 0
    for j in range(i + 1):
        tot += (0 if j > 32 else P4[j]) * (0 if i - j < 0 or i - j > 32 else P4[i - j])
P5 += [tot]

Steps 1 and 2

n P(n-th byte strictly below 0x80) P(n-th byte equal t0 0x00)
1 0.5 0.00390625
2 0.5 0.00390625
3 0.5 0.00390625
4 0.5 0.00390625
5 0.5 0.00390625
6 0.5 0.00390625
7 0.5 0.00390625
8 0.5 0.00390625
9 0.5 0.00390625
10 0.5 0.00390625
11 0.5000000000000022 0.003906250000000017
12 0.5000000000005779 0.003906250000004515
13 0.500000000147937 0.003906250001155758
14 0.5000000378718793 0.003906250295874057
15 0.5000096953883757 0.003906325745221685
16 0.5024943531225264 0.003925737133769738
17 0.6856540772660831 0.005356672478641274
18 0.732002063802848 0.00571876612345975
19 0.5794447966936758 0.004526912474169342
20 0.5548699108661184 0.00433492117864155
21 0.7302447613491383 0.005705037198040143
22 1 0.013769190314648471
23 0.7988347212307143 0.0062408962596149555
24 1 0.01673659670574068
25 0.6672861472551118 0.005213173025430561
26 0.6084536955247551 0.00475354449628715
27 1 0.010576408771775197
28 0.9090048643960403 0.007101600503094065
29 0.6147582324995815 0.0048027986914029805
30 1 0.018431520780459707
31 1 0.01532567049808429
32 1 0.015625

Steps 3 and 4

n P(int encoded in n or less bytes) P(int encoded in n bytes)
33 1 0.5
32 0.5 0.498046875
31 0.001953125 0.00194549560546875
30 7.62939453125e-06 7.599592208862305e-06
29 2.9802322387695312e-08 2.9685907065868378e-08
28 1.1641532182693481e-10 1.1596057447604835e-10
27 4.547473508864641e-13 4.5297099404706387e-13
26 1.7763568394002505e-15 1.7694179454963432e-15
25 6.938893903907228e-18 6.911788849595091e-18
24 2.710505431213761e-20 2.6999175193730823e-20
23 1.0587911840678754e-22 1.0546552810051103e-22
22 4.135903062765157e-25 4.1197471914262116e-25
21 1.6155871338945066e-27 1.6092762466508639e-27
20 6.310887243642644e-30 6.2862353384799364e-30
19 2.465190516270689e-32 2.4555606790901042e-32
18 9.62983718058453e-35 9.592032971172553e-35
17 3.780420941197716e-37 3.7601704643843237e-37
16 2.025047681339295e-39 2.0134669072608612e-39
15 1.1580774078433875e-41 1.1528348927797675e-41
14 5.242515063619928e-44 5.219789174041295e-44
13 2.2725889578633377e-46 2.259623753322872e-46
12 1.2965204540465624e-48 1.2863913879993236e-48
11 1.0129066047238769e-50 1.0017653337056596e-50
10 1.1141271018217275e-52 1.1054229838387452e-52
9 8.704117982982246e-55 8.606909530474824e-55
8 9.720845250742335e-57 9.67463678030141e-57
7 4.6208470440925305e-59 4.584746676560557e-59
6 3.6100367531972894e-61 3.575329834504594e-61
5 3.470691869269522e-63 3.4540228349015315e-63
4 1.6669034367990625e-65 1.6538807536990699e-65
3 1.3022683099992676e-67 1.2782655245817819e-67
2 2.4002785417485644e-69 2.3634926637141035e-69
1 3.6785878034460756e-71 3.6785878034460756e-71
0 0 -

Step 5 (final)

n true P(signature encoded in n bytes) approx P(signature encoded in n bytes)
73 0.25 0.25
72 0.498046875 0.498046875
71 0.24999618530273438 0.24999618530273438
70 0.00194549560546875 0.00194549560546875
69 1.1384545359760523e-05 1.1384545359760523e-05
68 5.925585355726071e-08 5.925585355726071e-08
67 2.892219796990503e-10 2.892219796990503e-10
66 1.355374146250199e-12 1.355374146250199e-12
65 6.1756833371132136e-15 6.1756833371132136e-15
64 2.756615787279917e-17 2.756615787279917e-17
63 1.2112715902343692e-19 1.2112715902343692e-19
62 5.256797416259847e-22 5.256797416259847e-22
61 2.2586192121744877e-24 2.2586192121744877e-24
60 9.624226303212785e-27 9.624226303212785e-27
59 4.07254738627694e-29 4.072547386276944e-29
58 1.7131372549304673e-31 1.713137255023982e-31
57 7.169683842881179e-34 7.1696706534513e-34
56 2.9891380332435605e-36 2.9872651970567073e-36
55 1.2956630027191572e-38 1.2397960137144533e-38
54 5.925483536717171e-41 5.127701405580587e-41
53 2.7235728112201808e-43 2.1142381377301136e-43
52 1.2459299337274498e-45 8.693234038692619e-46
51 5.983549743027845e-48 3.565517715576946e-48
50 3.2760192772710354e-50 1.4590784706209326e-50
49 2.359191106111631e-52 5.958502279666487e-53
48 1.7750841783708837e-54 2.4287028451054517e-55
47 1.6539306964251422e-56 9.88228803600071e-58
46 1.102991219208898e-58 4.0146310872297853e-60
45 7.884467470307591e-61 1.6285130509362473e-62
44 6.521091812501353e-63 6.596917318059999e-65
43 4.200123883671048e-65 2.6689279417579225e-67
42 2.932227991076294e-67 1.0784902563080695e-69
41 3.527074924366427e-69 4.3532442787771506e-72
40 5.027557783414213e-71 1.7548964384219258e-74
39 1.9638714576070266e-73 6.640843455942346e-77
38 7.671341484971243e-76 2.5103994919136894e-79
37 2.9966267864896135e-78 9.479373081444921e-82
36 1.170568621835192e-80 3.5751945889070283e-84
35 4.572644358294181e-83 1.346683229638529e-86
34 1.7863214597443312e-85 5.065648722598634e-89
33 6.979552616235899e-88 1.9026625310241262e-91
32 2.7281617548532366e-90 7.134984491340473e-94
31 1.0675258167598797e-92 2.6709740120577944e-96
30 4.1840836696378804e-95 9.979862137444205e-99
29 1.644408638485888e-97 3.721184390737363e-101
28 6.512637042190922e-100 1.38436919298265e-103
27 2.614781160445145e-102 5.137307552084053e-106
26 1.0754772340117051e-104 1.901141775031105e-108
25 4.8134786169933013e-107 7.013760888786629e-111
24 2.6628712878241215e-109 2.5785885620539077e-113
23 1.5159853243829836e-111 9.443073347365385e-116
22 7.834838655424536e-114 3.4427871578936298e-118
21 4.38884078738162e-116 1.2487788240127563e-120
20 2.9834225546535107e-118 4.502808259661381e-123
19 2.244146624653679e-120 1.612333686727708e-125
18 1.866099448625061e-122 5.725616785254645e-128
17 1.4453207033504319e-124 2.012912151066086e-130
16 1.1341555750752545e-126 6.989278302312799e-133
15 6.219695625039266e-129 2.38891348223582e-135
14 4.685964220463818e-131 7.998594248557433e-138
13 3.4863685353971767e-133 2.6037090652856228e-140
12 1.8210233517078607e-135 8.136590829017571e-143
11 1.4990521508014672e-137 2.3837668444387415e-145
10 1.7388630572545956e-139 6.207726157392556e-148
9 1.3532008227662222e-141 1.2124465151157336e-150
8 0.0 0.0