Cryptography Reference
In-Depth Information
In general, if we use an alphabet of size
n
, the enciphering transformation of a shift cipher
is
C P+ s (mod n )
0 C < n .
We allow the shift
s
to be any number between 1 and
n
1.
E XAMPLE .
Encipher the message
THIS MESSAGE IS TOP SECRET
using the ordinary alphabet and a Caesar cipher with a shift of 3. When each letter is con-
verted to a number, and we group into blocks of length 5, we get
19 7 8 18 12
4 18 18 0 6
4 8 18 19 14
15 18 4 2 17
4 19.
(Here, we group the items in blocks for readability.) After applying the enciphering trans-
formation, each number becomes
22 10 11 21 15
7 21 21 3 9
7 11 21 22 17
18 21 7 5 20
7 22
and the ciphertext message is sent as
WKLVP
HVVDI
HLVWR
SVHFU
HW.
Hopefully you can see that by shifting each of the ciphertext letters back three letters; that
is, by applying the deciphering transformation
P C 3 (mod 26),
the plaintext is regained.
When writing programs to encipher/decipher, we will rarely use the ordinary alphabet.
Computers already have a character-number association, since everything must be stored
as a binary number inside a digital computer. There are various character representation
schemes out there; most notable are ASCII, and EBCDIC. Java uses a character mapping
called Unicode; programs using Java over the Internet usually encode characters in Unicode.
The following is a partial listing of the Unicode sequence (the first 255 characters happen
to be the same characters as in the ASCII sequence). The characters and their associated num-
ber code are listed. The first 32 characters (0 through 31) are nonprintable characters, and
character #32 is the space. Thus, they are not shown here. (See Table 5.2.)
We will call the previous character-number association the “ASCII alphabet.” In general,
however, we will regard a message as merely an array of bytes, and will not concern our-
selves with what the bytes represent.
Java Algorithm. To see the character encoding used by your system, the following
Java program will help.
Search WWH ::




Custom Search