 .  We now describe a simple way to do this.  Note
that in any actual deployed implementation it is crucial
that you add extra random characters (``salt'') at the beginning
of each block of the message, so that the same plain text encodes 
differently each time.  This helps thwart chosen plain text attacks.
.  We now describe a simple way to do this.  Note
that in any actual deployed implementation it is crucial
that you add extra random characters (``salt'') at the beginning
of each block of the message, so that the same plain text encodes 
differently each time.  This helps thwart chosen plain text attacks. 
Suppose  is a sequence of capital letters and spaces, and that
 is a sequence of capital letters and spaces, and that  does not begin with a space.  We encode
does not begin with a space.  We encode  as a number in base
 as a number in base  as follows: a single space corresponds to 0
, the letter
as follows: a single space corresponds to 0
, the letter  to
 to  ,
,
 to
 to  ,
,  ,
,  to
 to  .  Thus ``RUN NIKITA'' is a number
written in base
.  Thus ``RUN NIKITA'' is a number
written in base  :
:
| RUN NIKITA  |  | |
|  | ||
|  (in decimal)  | 
 and
read off the letter corresponding to each remainder:
 and
read off the letter corresponding to each remainder:
 
If 
 , then any sequence of
, then any sequence of  letters can be encoded as above
using a positive integer
 letters can be encoded as above
using a positive integer  .  Thus if we can encrypt integers
of size at most
.  Thus if we can encrypt integers
of size at most  , then we must break our message up into blocks
of size at most
, then we must break our message up into blocks
of size at most 
 .
.
 , inclusive. 
This number is obtained from the letter using the ord
command.
, inclusive. 
This number is obtained from the letter using the ord
command.  
sage: def encode(s):
...    s = str(s)      # make input a string
...    return sum(ord(s[i])*256^i for i in range(len(s)))
sage: def decode(n): 
...    n = Integer(n)  # make input an integer
...    v = []
...    while n != 0:
...        v.append(chr(n % 256))
...        n //= 256    # this replaces n by floor(n/256). 
...    return ''.join(v)
sage: m = encode('Run Nikita!'); m
40354769014714649421968722
sage: decode(m)
'Run Nikita!'
William 2007-06-01