Text to integer
In public-key cryptography, one often needs to calculate the exponentiation. For example, you have a messageand some integer like Part of the encryption process is to calculate
But wait! How can you calculate something like that ifis 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 messageseemed too long. Bob simply used instead.
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.
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 encryptEverybody 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 characterto to to to and to
Or, it mapsto:
Using hexadecimal system, this would be:
In the hexadecimal system, each number occupies two places, so we can write:
The textis finally converted to the number as follows:
If for some strange reason, somebody wants to calculatewhere 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.