18 Gematria: Numeric encoding of text using ASCII values

 

Gematria is a system for assigning a number to a word by summing the numeric values of each of the characters (https://en.wikipedia.org/wiki/Gematria). In the standard encoding (Mispar hechrechi), each character of the Hebrew alphabet is assigned a numeric value ranging from 1 to 400, but there are more than a dozen other methods for calculating the numeric value for the letters. To encode a word, these values are added together. Revelation 13:18 from the Christian Bible says, “Let the one who has insight calculate the number of the wild beast, for it is a man’s number, and its number is 666.” Some scholars believe that number is derived from the encoding of the characters representing Nero Caesar’s name and title and that it was used as a way of writing about the Roman emperor without naming him.


We will write a program called gematria.py that will numerically encode each word in a given text by similarly adding numeric values for the characters in each word. There are many ways we could assign these values. For instance, we could start by giving “a” the value 1, “b” the value 2, and so forth. Instead, we will use the ASCII table (https://en.wikipedia.org/wiki/ASCII) to derive a numeric value for English alphabet characters. For non-English characters, we could consider using a Unicode value, but this exercise will stick to ASCII letters.

The input text may be entered on the command line:

18.1 Writing gematria.py

 
 
 
 

18.1.1 Cleaning a word

 
 

18.1.2 Ordinal character values and ranges

 
 
 
 

18.1.3 Summing and reducing

 
 

18.1.4 Using functools.reduce

 
 
 

18.1.5 Encoding the words

 
 
 

18.1.6 Breaking the text

 
 

18.2 Solution

 
 

18.3 Discussion

 
 

18.3.1 Writing word2num()

 

18.3.2 Sorting

 

18.3.3 Testing

 
 

18.4 Going further

 
 
 
 

Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest