Elementary Cryptography
Elementary Cryptography
Encryption is the process of encoding a message so that its meaning is not obvious;
decryption is the reverse process, transforming an encrypted message back into its normal,
original form. Alternatively, the terms encode and decode or encipher and decipher are used
instead of encrypt and [Link] is, we say that we encode, encrypt, or encipher the
original message to hide its meaning. Then, we decode, decrypt, or decipher it to reveal the
original message. A system for encryption and decryption is called a cryptosystem.
The original form of a message is known as plaintext, and the encrypted form is called
cipher text. For convenience, we denote a plaintext message P as a sequence of individual
characters P = <p1, p2, …, pn>. Similarly, cipher text is written as C = <c1, c2, …,cm>.
We use this formal notation to describe the transformations between plaintext and cipher text.
For example:
we write C = E (P) and P = D(C), where C represents the cipher text, E is the
encryption rule, P is the plaintext, and D is the decryption rule.
P = D (E(P)).
In other words, we want to be able to convert the message to protect it from an intruder, but
we also want to be able to get the original message back so that the receiver can read it
properly.
The cryptosystem involves a set of rules for how to encrypt the plaintext and how to decrypt
the cipher text. The encryption and decryption rules, called algorithms, often use a device
called a key, denoted by K, so that the resulting cipher text depends on the original plaintext
message, the algorithm, and the key value. We write this dependence as C =E (K, P).
Essentially, E is a set of encryption algorithms, and the key K selects one specific algorithm
from the set.
There are many types of encryption. In the next sections we look at two simple forms of
encryption: substitutions in which one letter is exchanged for another and transpositions,
in which the order of the letters is rearranged.
Cryptanalyst: cryptanalyst is a person who studies encryption and encrypted message and
tries to find the hidden meanings (to break an encryption).
Confusion: it is a technique for ensuring that ciphertext has no clue about the original
message.
Diffusion: it increases the redundancy of the plaintext by spreading it across rows and
columns.
Example:
Plain text(P)- H E L LO (H=7,E=4,L=11,L=11,O=14)
Key (K)=15
Cipher text (C)= 7+15,4+15,11+15,11+15,14+15
= 22,19, 26,26,(29%26)=3
= W T A AD
Affine cipher: C= (P+K) mod 26
It is the combination f additive
P= (C-K)and multiplica
mod 26 tive cipher
o
In polyalphabetic cipher each occurrence of a character may have different substitution. The
relationship between characters in plain text and cipher text is 1 to many.
Auto key cipher
Playfair cipher
Vigegeire cipher
Hill cipher
Example: A T T A C K
0 19 19 0 2 10
Key=12
12 0 19 19 0 2
Playfair cipher
In playfair cipher the secret key is made of 25 characters arranged in 5x5 matrix
Rules:
- If 2 letters in a plaintext are located in the same row of the secret key then the
corresponding encrypted character for each letter is next letter to the right.
If 2 letters in a pair are in same column then the corresponding encrypted
character is next below in the same column.
If 2 letters are neither in same row or in same column then encrypted
character is in its own row but in the same column as the other character.
Example:
L G D B A
Q M H E C
K= U R N I/J F
XV S O K
ZY W T P
Plain text= HELLO
Vigener cipher:
The key stream is the repetition of the initial secret key stream of length m.
(1<=m<=26)
Example:
Plaintext- A B C D E F G H
Ks= 0, 5, 8
A B C D E F G H (B=1 =>1+5=6=>G)
0 5 8 0 5 8 0 5
0 6 10 3 9 13 6 12
A G K D J N G M <= ciphertext
Transposition cipher:
keys:
So far, the encryption algorithms we have seen are trivial, intended primarily to demonstrate
the concepts of substitution and permutation. At the same time, we have examined several
approaches cryptanalysts use to attack encryption algorithms. Now we examine algorithms
that are widely used in the commercial world.
For each type of encryption we considered, has the advantages and disadvantages. But there
is a broader question: What does it mean for a cipher to be "good"? The meaning of good
depends on the intended use of the cipher. A cipher to be used by military personnel in the
field has different requirements from one to be used in a secure installation with substantial
computer support. In this section, we look more closely at the different characteristics of
ciphers.
Shannon's Characteristics of "Good" Ciphers
In 1949, Claude Shannon [SHA49] proposed several characteristics that identify a
good cipher.
1. The amount of secrecy needed should determine the amount of labor appropriate for
the encryption and decryption.
2. The set of keys and the enciphering algorithm should be free from complexity.
This principle implies that we should restrict neither the choice of keys nor the types of
plaintext on which the algorithm can work. For instance, an algorithm that works only on
plaintext having an equal number of A's and E's is useless. Similarly, it would be difficult
to select keys such that the sum of the values of the letters of the key is a prime number.
Restrictions such as these make the use of the encipherment prohibitively complex. If the
process is too complex, it will not be used. Furthermore, the key must be transmitted,
stored, and remembered, so it must be short.
3. The implementation of the process should be as simple as possible.
Principle 3 was formulated with hand implementation in mind: A complicated algorithm is
prone to error or likely to be forgotten. With the development and popularity of digital
computers, algorithms far too complex for hand implementation became feasible. Still, the
issue of complexity is important. People will avoid an encryption algorithm whose
implementation process severely hinders message transmission, thereby undermining
security. And a complex algorithm is more likely to be programmed incorrectly.
4. Errors in ciphering should not propagate and cause corruption of further information
in the message.
Principle 4 acknowledges that humans make errors in their use of enciphering algorithms.
One error early in the process should not throw off the entire remaining ciphertext. For
example, dropping one letter in a columnar transposition throws off the entire remaining
encipherment. Unless the receiver can guess where the letter was dropped, the remainder of
the message will be unintelligible. By contrast, reading the wrong row or column for a
polyalphabetic substitution affects only one character and remaining characters are
unaffected.
5. The size of the enciphered text should be no larger than the text of the original
message.
The idea behind principle 5 is that a ciphertext that expands dramatically in size
cannotpossibly carry more information than the plaintext, yet it gives the cryptanalyst more
datafrom which to infer a pattern. Furthermore, a longer ciphertext implies more space for
storage and more time to communicate.
We can divide all the cryptography algorithms (ciphers) into two groups: symmetric key
cryptography algorithms and asymmetric cryptography algorithms. Figure shows the
taxonomy.
CRYPTOGRAPHY
1. Symmetric·Key Cryptography
In symmetric-key cryptography, the same key is used by both parties. The sender uses this
key and an encryption algorithm to encrypt data; the receiver uses the same key and the
corresponding decryption algorithm to decrypt the data.
2. Asymmetric-Key Cryptography:
In asymmetric or public-key cryptography, there are two keys: a private key and a public
key. The private key is kept by the receiver. The public key is announced to the public.
Fig 7:Asymmetric-key Cryptography
Encryption involves applying an operation (an algorithm) to the data to be encrypted using
the private key to make them unintelligible. The slightest algorithm (such as an exclusive
OR) can make the system nearly tamper proof (there being so such thing as absolute
security).
However, in the 1940s, Claude Shannon proved that to be completely secure, private-key
systems need to use keys that are at least as long as the message to be encrypted. Moreover,
symmetric encryption requires that a secure channel be used to exchange the key, which
seriously diminishes the usefulness of this kind of encryption system.
The main disadvantage of a secret-key cryptosystem is related to the exchange of keys.
Symmetric encryption is based on the exchange of a secret (keys). The problem of key
distribution therefore arises:
Moreover, a user wanting to communicate with several people while ensuring separate
confidentiality levels has to use as many private keys as there are people. For a group
of N people using a secret-key cryptosystem, it is necessary to distribute a number of keys
equal to N * (N-1) / 2.
In the 1920s, Gilbert Vernam and Joseph Mauborgne developed the One-Time Pad method
(sometimes called "One-Time Password" and abbreviated OTP), based on a randomly
generated private key that is used only once and is then destroyed. During the same period,
the Kremlin and the White House were connected by the famous red telephone, that is, a
telephone where calls were encrypted thanks to a private key according tothe one-time
pad method. The private key was exchanged thanks to the diplomatic bag (playing the role
ofsecure channel).
Advantages:
High diffusion: information from one plaintext symbol is diffused into several
ciphertext symbols.
Immunity to tampering: difficult to insert symbols without detection.
Disadvantages:
Slowness of encryption: an entire block must be accumulated before encryption /
decryption can begin.
Error propagation: An error in one symbol may corrupt the entire block.
Simple substitution is an example of a stream cipher. Columnar transposition is a block
cipher.
The Data Encryption Standard (DES), a system developed for the U.S. government, was
intended for use by the general public. It has been officially accepted as a cryptographic
standard both in the United States and abroad.
The DES algorithm is a careful and complex combination of two fundamental building
blocks of encryption: substitution and transposition. The algorithm derives its strength from
repeated application of these two techniques, one on top of the other, for a total of 16 cycles.
The sheer complexity of tracing a single bit through 16 iterations of substitutions and
transpositions has so far stopped researchers in the public from identifying more than a
handful of general properties of the algorithm. The algorithm begins by encrypting the
plaintext as blocks of 64 bits. The key is 64 bits long, but in fact it can be any 56-bit number.
(The extra 8 bits are often used as check digits and do not affect encryption in normal
implementations.) The user can change the key at will any time there is uncertainty about the
Features: –
Block size = 64 bits
– Key size = 56 bits (in reality, 64 bits, but 8 are used
as parity-check bits for error control, see next slide)
– Number of rounds = 16
– 16 intermediary keys, each 48 bits
key 56 bit
plaintext ciphertext
DES
64 bit 64 bit
Working principle:
64 bit plaintext
Initial permutation
56 bit cipher key
Round 1
Round 2
Round key generation
.
.
.
Round 16
final permutation
The AES is likely to be the commercial-grade symmetric algorithm of choice for years, if not
decades. Let us look at it more closely.
The AES Contest
In January 1997, NIST called for cryptographers to develop a new encryption system. As
with the call for candidates from which DES was selected, NIST made several important
restrictions. The algorithms had to be
Unclassified
publicly disclosed
available royalty-free for use worldwide
symmetric block cipher algorithms, for blocks of 128 bits
usable with key sizes of 128, 192, and 256 bits
1. KeyExpansions—round keys are derived from the cipher key using Rijndael's key
schedule. AES requires a separate 128-bit round key block for each round plus one
more.
2. InitialRound
1. AddRoundKey—each byte of the state is combined with a block of the round
key using bitwise xor.
3. Rounds
1. SubBytes—a non-linear substitution step where each byte is replaced with
another according to a lookup table.
2. ShiftRows—a transposition step where the last three rows of the state are
shifted cyclically a certain number of steps.
3. MixColumns—a mixing operation which operates on the columns of the state,
combining the four bytes in each column.
4. AddRoundKey
4. Final Round (no MixColumns)
1. SubBytes
2. ShiftRows
3. AddRoundKey.
The SubBytes steps
In the SubBytes step, each byte in the state is replaced with its entry in a fixed 8-bit lookup
table, S; bij =S(aij).
In the SubBytes step, each byte in the state matrix is replaced with a SubByte using
an 8-bit substitution box, the Rijndael S-box. This operation provides the non-linearity in the
cipher. The S-box used is derived from the multiplicative inverse over GF(28), known to have
good non-linearity properties. To avoid attacks based on simple algebraic properties, the S-
box is constructed by combining the inverse function with an invertible affine transformation.
The S-box is also chosen to avoid any fixed points (and so is a derangement), i.e.,
, and also any opposite fixed points, i.e., . While
performing the decryption, Inverse SubBytes step is used, which requires first taking
the affine transformation and then finding the multiplicative inverse (just reversing the steps
used in SubBytes step).
In the ShiftRows step, bytes in each row of the state are shifted cyclically to the left. The
number of places each byte is shifted differs for each row.
The ShiftRows step operates on the rows of the state; it cyclically shifts the bytes in each row
by a certain offset. For AES, the first row is left unchanged. Each byte of the second row is
shifted one to the left. Similarly, the third and fourth rows are shifted by offsets of two and
three respectively. For blocks of sizes 128 bits and 192 bits, the shifting pattern is the same.
Row n is shifted left circular by n-1 bytes. In this way, each column of the output state of
the ShiftRows step is composed of bytes from each column of the input state. (Rijndael
variants with a larger block size have slightly different offsets). For a 256-bit block, the first
row is unchanged and the shifting for the second, third and fourth row is 1 byte, 3 bytes and 4
bytes respectively—this change only applies for the Rijndael cipher when used with a 256-bit
block, as AES does not use 256-bit blocks. The importance of this step is to avoid the
columns being linearly independent, in which case, AES degenerates into four independent
block ciphers.
The MixColumns step
In the MixColumns step, each column of the state is multiplied with a fixed polynomial c(x).
In the MixColumns step, the four bytes of each column of the state are combined using an
invertible linear transformation. The MixColumns function takes four bytes as input and
outputs four bytes, where each input byte affects all four output bytes. Together
with ShiftRows, MixColumns provides diffusion in the cipher.
During this operation, each column is multiplied by a fixed matrix:
Matrix multiplication is composed of multiplication and addition of the entries, and here
the multiplication operation can be defined as this: multiplication by 1 means no change,
multiplication by 2 means shifting to the left, and multiplication by 3 means shifting to
the left and then performing XOR with the initial unshifted value. After shifting, a
conditional XOR with 0x1B should be performed if the shifted value is larger than 0xFF.
(These are special cases of the usual multiplication in GF. Addition is simply XOR.
In more general sense, each column is treated as a polynomial over GFand is then
multiplied modulo x4+1 with a fixed polynomial c(x) = 0x03 · x3 + x2 + x + 0x02. The
coefficients are displayed in their hexadecimal equivalent of the binary representation of
bit polynomials from GF(2)[x]. The MixColumns step can also be viewed as a
multiplication by the shown particular MDS matrix in the finite field GF(28). This
process is described further in the article Rijndael mix columns.
The AddRoundKey step
In the AddRoundKey step, each byte of the state is combined with a byte of the round
subkey using the XORoperation (⊕).
In the AddRoundKey step, the subkey is combined with the state. For each round, a
subkey is derived from the main keyusing Rijndael's key schedule; each subkey is the
same size as the state. The subkey is added by combining each byte of the state with the
corresponding byte of the subkey using bitwise XOR.
Optimization of the cipher
On systems with 32-bit or larger words, it is possible to speed up execution of this cipher
by combining the SubBytes andShiftRows steps with the MixColumns step by
transforming them into a sequence of table lookups. This requires four 256-entry 32-bit
tables, and utilizes a total of four kilobytes (4096 bytes) of memory — one kilobyte for
each table. A round can then be done with 16 table lookups and 12 32-bit exclusive-or
operations, followed by four 32-bit exclusive-or operations in the AddRoundKey steps.
If the resulting four-kilobyte table size is too large for a given target platform, the table
lookup operation can be performed with a single 256-entry 32-bit (i.e. 1 kilobyte) table
by the use of circular rotates.
Using a byte-oriented approach, it is possible to combine the SubBytes, ShiftRows,
and MixColumns steps into a single round operation.
PSEUDO-RANDOMNESS
Forcryptography, the use of pseudorandom number generators (whether hardware or software
or some combination) is insecure. When random values are required in cryptography, the
goal is to make a message as hard to crack as possible, by eliminating or obscuring the
parameters used to encrypt the message (the key) from the message itself or from the context
in which it is carried. Pseudorandom sequences are deterministic and reproducible; all that is
required in order to discover and reproduce a pseudorandom sequence is the algorithm used
to generate it and the initial seed. So the entire sequence of numbers is only as powerful as
the randomly chosen parts - sometimes the algorithm and the seed, but usually only the seed.
There are many examples in cryptographic history of cyphers, otherwise excellent, in which
random choices were not random enough and security was lost as a direct consequence.
The World War II Japanese PURPLE cypher machine used for diplomatic communications is
a good example. It was consistently broken throughout WWII, mostly because the "key
values" used were insufficiently random. They had patterns, and those patterns made any
intercepted traffic readily decryptable. Had the keys (i.e. the initial settings of the stepping
switches in the machine) been made unpredictably (i.e. randomly), that traffic would have
been much harder to break, and perhaps even secure in practice.
Users and designers of cryptography are strongly cautioned to treat their randomness needs
with the utmost care. Absolutely nothing has changed with the era of computerized
cryptography, except that patterns in pseudorandom data are easier to discover than ever
before. Randomness is, if anything, more important than ever.
HASHING
A cryptographic hash function is a hash function which is considered practically impossible
to invert, that is, to recreate the input data from its hash value alone. These one-way hash
functions have been called "the workhorses of modern cryptography". The input data is often
called the message, and the hash value is often called the message digest or simply the digest.
The ideal cryptographic hash function has four main properties: