## Section12.3Text

We describe how a sequence of several characters (often called a string) can be encoded into a single number. This is often the first step in many cryptographic protocols, after which the number thus obtained is then encrypted with an encryption function.

### Strategy12.3.1.Decimal representation of text.

To compute the decimal representation of a word proceed as follows.

#### (a)

Encode the characters in the given text into numbers in $$\Z_{27}$$ using the function $$C:\A\to\Z_{27}$$ from Figure 12.3.2.

#### (b)

Consider these numbers as coefficient of a base $$27$$ expansion. Evaluate the base $$27$$ expansion to obtain the decimal representation of the text.

We demonstrate how to compute a decimal representation of the word $$\mathtt{wombat}$$ by following the steps given in the strategy above.

We find a representation of the word $$\mathtt{wombat}$$ as an integer.

#### (a)

The function $$C$$ defined in Figure 12.3.2 encodes the letters in $$\mathtt{wombat}$$ as the numbers $$23\text{,}$$ $$15\text{,}$$ $$13\text{,}$$ $$2\text{,}$$ $$1\text{,}$$ $$20\text{.}$$

#### (b)

We now consider these as the values of the digits of a base $$27$$ number. We obtain
\begin{equation*} 23\cdot 27^5+15\cdot27^4+13\cdot27^3+2\cdot27^2+1\cdot27+20 \cdot 1=338253860 \end{equation*}

So, the decimal representation of the word $$\mathtt{wombat}$$ is the decimal number $$338253860\text{.}$$

We demonstrate the strategy in the solution of Problem 12.3.3.

Compute a decimal representation of the word $$\mathtt{dog}\text{.}$$

The representation of $$\mathtt{dog}$$ as a decimal number is $$3328\text{.}$$

Solution.

Encoding the letters in $$\mathtt{dog}$$ by the function $$C$$ from Figure 12.3.2 we obtain

\begin{equation*} C(\mathtt{d})=4, C(\mathtt{o})=15, C(\mathtt{g})=7\text{.} \end{equation*}

Considering as the values of the digits of a base 27 representation, we write out the base 27 expansion and evaluate it:

\begin{equation*} 4\cdot27^2+15\cdot27+7 \cdot 1=3328 \end{equation*}

So, the decimal representation of the word $$\mathtt{dog}$$ is the decimal number $$3328\text{.}$$

Now use the methods described above to compute a representation of a word as an integer.

Fill in the operation table for the binary operation $$\otimes$$ on the set $$\mathbb{Z}_{6}$$ defined by $$a \otimes b = (a \cdot b)\bmod 6$$ :

The left column represents the $$a$$ values and the top row represents the $$b$$ values.

 $$\otimes$$ 0 1 2 3 4 5 0 0 0 0 0 0 1 5 2 4 2 4 3 3 0 4 0 2 5 0 4 1

We can also work backwards to find the text that is encoded in a given decimal number.

### Strategy12.3.2.Conversion of decimal numbers to text.

To convert a decimal number to text proceed as follows.

#### (a)

Find the base 27 expansion of the number.

#### (b)

Decode each digit of the base 27 expansion using the decoding function $$C^{-1}:\Z_{27}\to\A$$ given by from Figure 12.3.2 to obtain the characters of the text.

Find the text encoded as the number $$2234\text{.}$$

The text represented by the decimal number $$2234$$ is $$\mathtt{cat}$$

Solution.

We start by converting the decimal number $$2234$$ to a base $$27$$ number with the method used by the base conversion algorithm (Algorithm 11.5.1):

 $$2234 \fdiv 27=82$$ $$2234 \fmod 27=20$$ $$82\fdiv27=3$$ $$82 \fmod 27 = 1$$ $$3\fdiv 27=0$$ $$3 \fmod 27 = 3$$

Thus the base $$27$$ expansion of $$2234$$ is $$2234=3\cdot 27^2+1\cdot 27+20 \cdot 1\text{.}$$ We decode the digits of the base $$27$$ expansion number into letters using the function $$C^{-1}$$ from Figure 12.3.2:

\begin{equation*} C^{-1}(3) = \mathtt{c}, C^{-1}(1) = \mathtt{a}, C^{-1}(20) = \mathtt{t} \end{equation*}

So, the word encoded as the number $$2234$$ is $$\mathtt{cat}\text{.}$$

In Checkpoint 12.3.6 apply these methods to recover a word that is encoded in a number.

Let S be a set and let * : S $$\times$$ S $$\to$$ S be a binary operation on S. We read a * b as 'a star b'.

If

• select

• a * (b * c)

• (a * b) * c

• (a * b) * (a * c)

• (a * b) * c

= (a * b) * c
• select

• for a=1 and b=2 and c=3

• for all a in S, all b in S, and all c in S

• for a=1 and b=2 and c=3

• for some integers a, b, and c

• for all a in S and some b in S

then the binary operation * is called

• select

• associative

• commutative

• distributive

• transitive

.

$${\text{a * (b * c)}}$$
$$\text{for all a in S, all b in S, and all c in S}$$
$$\text{associative}$$