PY
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
import string
import math
import random
# using a longer alphabet(A - z) so lower and uppercase can be encoded
alphabet = [c for c in string.ascii_letters]
alphabet.append(' ')
# adding additional characters(you can add your own to the string)
alphabet.extend(*'1234567890.,!?'.split())
m = len(alphabet) # m = 53
print('alphabet =',*alphabet)
print(f'\n{m = }')
# possible values for a with m = 53 (find coprimes)
a_vals = set()
for n in range(m):
if math.gcd(n,m)==1:
a_vals.add(n)
# possible values for b
b_vals = range(m)
# (optional)
# choose a random item from a_vals for a
# a<=1
a = random.sample(a_vals, 1)[0]
print(f'{a = }')
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run