Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Created January 21, 2026 17:46
Show Gist options
  • Select an option

  • Save peteristhegreat/9c31c88e005060fabf4695062c0c75d4 to your computer and use it in GitHub Desktop.

Select an option

Save peteristhegreat/9c31c88e005060fabf4695062c0c75d4 to your computer and use it in GitHub Desktop.
Primes, Alpha Code

https://oeis.org/A000040

Primes mapped to alpha values.

a 2
b 3
c 5
d 7
e 11
f 13
g 17
h 19
i 23
j 29
k 31
l 37
m 41
n 43
o 47
p 53
q 59
r 61
s 67
t 71
u 73
v 79
w 83
x 89
y 97
z 101

In 5th grade, we had to use primes to make a product that would represent a word. To decode a number to a word you had to do the prime factorization.

Everyone had calculators that could represent 8 digits.

We had fun doing prime factorization with words that day. I frustrated some classmates by giving them the coded words:

math is power

Power comes out to 138731263, which did not fit on anyone's calculator. :)

So for a 5th grader to solve it you had to be a bit smarter if you didn't want to take all day.

You would try the vowels first or other common english letters first before just all the primes in order.

Dividing by 11, would get you a number that would fit on the calculator screen.

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
alpha = 'abcdefghijklmnopqrstuvwxyz'
for p,a in zip(primes, alpha):
print(a, p)
p2a = { p:a for p,a in zip(primes, alpha)}
a2p = { a:p for p,a in zip(primes, alpha)}
def word_to_num(word):
prod = 1
for a in word:
prod *= a2p[a]
return prod
word_to_num('power')
# 138731263
word_to_num('math')
# 110618
word_to_num('is')
# 1541
138731263/11
# 12611933.0
p2a[11]
# 'e'
def num_to_word(num):
# try dividing by each prime
# if it is divisible, add it to the list of prime factorizations
primes = []
for p in p2a.keys():
if num%p == 0:
primes.append(p)
for p in primes:
print(p2a[p], end='')
num_to_word(138731263)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment