Text to integer

February 13, 2021

In public-key cryptography, one often needs to calculate the exponentiation. For example, you have a message

and some integer
like
Part of the encryption process is to calculate

But wait! How can you calculate something like that if

is a string.

Bob immediately had a few ideas when he came across this problem. Bob is never short of ideas. He knows how to solve problems. You know, you first translate a problem into a simpler one.

The message

seemed too long. Bob simply used

Bob wrote:

How can you convert this into a number? Well, here's what Bob did:

Looks nice, right?

But, to calculate the value of the tower Bob still had to assign some numbers to the letters

Bob did the following:

If other letters are needed Bob will simply define mappings for those letters too.

Thus:

Wow.

seems huge. Perhaps Bob's tower isn't so efficient after all. No worries, though.

Bob found a solution in seconds:

There is one small problem though:

But that's not such a big deal, right? Everybody knows nobody wants to encrypt

Everybody wants to encrypt

However, it turns out that cryptographers already have some clever solutions for converting text into an integer.

Somewhat boring way to convert text to an integer

First of all, there are many character encodings that map characters to numbers. For example, UTF-8 maps character

to
to
to
to
and
to

Or, it maps

to:

Using hexadecimal system, this would be:

In the hexadecimal system, each number occupies two places, so we can write:

The text

is finally converted to the number as follows: Beat Bob #1

If for some strange reason, somebody wants to calculate

where
is a totally meaningful message
it can be done just like that:

But that tends to be kind of a large number, right? No worries! This is where modular arithmetic comes into play.