0% found this document useful (0 votes)
65 views30 pages

Unit 2 - Symmetric Key Cryptography

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views30 pages

Unit 2 - Symmetric Key Cryptography

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

UNIT II CRYPTOGRAPHY & NETWORK SECURITY

Symmetric Key Cryptography


Symmetric-Key Encipherment
In symmetric-key encipherment (sometimes called secret-key encipherment or secret key
cryptography), an entity, say Alice, can send a message to another entity, say Bob, over an
insecure channel with the assumption that an adversary, say Eve, cannot understand the
contents of the message by simply eavesdropping over the channel. Alice encrypts the
message using an encryption algorithm; Bob decrypts the message using a decryption
algorithm.
Symmetric-key encipherment uses a single secret key for both encryption and decryption.
Encryption/decryption can be thought of as electronic locking.
In symmetric key enciphering, Alice puts the message in a box and locks the box using the
shared secret key; Bob unlocks the box with the same key and takes out the message.
General idea of Symmetric key cipher:

An entity, Alice, can send a message to another entity, Bob, over an insecure channel with
the assumption that an adversary, Eve, cannot understand the contents of the message by
simply eavesdropping over the channel.
The original message from Alice to Bob is called plaintext; the message that is sent
through the channel is called the ciphertext. To create the ciphertext from the plaintext,
Alice uses an encryption algorithm and a shared secret key. To create the plaintext from
ciphertext, Bob uses a decryption algorithm and the same secret key. We refer to
encryption and decryption algorithms as ciphers. A key is a set of values (numbers) that
the cipher, as an algorithm, operates on.
The symmetric-key encipherment uses a single key (the key itself may be a set of values)
for both encryption and decryption. In addition, the encryption and decryption algorithms
are inverses of each other. If P is the plaintext, C is the ciphertext, and K is the key, the
encryption algorithm Ek(x) creates the ciphertext from the plaintext; the decryption
algorithm Dk(x) creates the plaintext from the ciphertext.
Encryption: C = Ek(P) Decryption: P = Dk(C)

1
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

MODERN BLOCK CIPHERS

A symmetric-key modern block cipher encrypts an n-bit block of plaintext or


decrypts an n-bit block of ciphertext. The encryption or decryption algorithm uses a
k-bit key. The decryption algorithm must be the inverse of the encryption algorithm,
and both operations must use the same secret key so that Bob can retrieve the
message sent by Alice.

Figure shows the general idea of encryption and decryption in a modern block
cipher.

If the message has fewer than n bits, padding must be added to make it an n-bit
block; if the message has more than n bits, it should be divided into n-bit blocks and
the appropriate padding must be added to the last block if necessary. The common
values for n are 64, 128, 256, or 512 bits.

A modern block cipher can be designed to act as a substitution cipher or a


transposition cipher. This is the same idea as is used in traditional ciphers, except
that the symbols to be substituted or transposed are bits instead of characters.

Modern block ciphers are designed as substitution ciphers because the inherent
characteristics of transposition vulnerable to exhaustive-search attacks.

Components of a Modern Block Cipher


1.P-Boxes

A P-box (permutation box) parallels the traditional transposition cipher for


characters. It transposes bits. We can find three types of P-boxes in modern block
ciphers: straight P-boxes, expansion P-boxes, and compression P-boxes.

2
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

i) Straight P-Boxes : A straight P-Box with n inputs and n outputs is a permutation.


There are n! possible mappings.

ii) Compression P-Boxes : A compression P-box is a P-box with n inputs and m


outputs where m < n. Some of the inputs are blocked and do not reach the output.
The compression P-boxes used in modern block ciphers normally are keyless with a
permutation table showing the rule for transposing bits. We need to know that a
permutation table for a compression P-box has m entries, but the content of each
entry is from 1 to n with some missing values.

iii) Expansion P-Boxes: An expansion P-box is a P-box with n inputs and m


outputs where m > n. Some of the inputs are connected to more than one input.The
expansion P-boxes used in modern block ciphers normally are keyless, where a
permutation table shows the rule for transposing bits.

2.S-Boxes:

An S-box (substitution box) can be thought of as a miniature substitution cipher.


However, an S-box can have a different number of inputs and outputs. In other
words, the input to an S-box could be an n-bit word, but the output can be an m-bit
word, where m and n are not necessarily the same. Although an S-box can be keyed
or keyless, modern block ciphers normally use keyless S-boxes, where the mapping
from the inputs to the outputs is predetermined.

3
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

The following table defines the input/output relationship for an S-box of size 3 × 2.
The leftmost bit of the input defines the row; the two rightmost bits of the input
define the column. The two output bits are values on the cross section of the
selected row and column.

Based on the table, an input of 010 yields the output 01. An input of 101 yields the
output of 00.

3.Exclusive-Or:

An important component in most block ciphers is the exclusive-or operation.

4.Circular Shift

Another component found in some modern block ciphers is the circular shift
operation. Shifting can be to the left or to the right. The circular left-shift operation
shifts each bit in an n-bit word k positions to the left; the leftmost k bits are
removed from the left and become the rightmost bits. The circular right-shift
operation shifts each bit in an n-bit word k positions to the right; the rightmost k
bits are removed from the right and become the leftmost bits.

4
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

Swap

The swap operation is a special case of the circular shift operation.

Split and Combine

Two other operations found in some block ciphers are split and combine. The split
operation normally splits an n-bit word in the middle, creating two equal-length
words. The combine operation normally concatenates two equal-length words to
create an n-bit word. These two operations are inverses of each other and can be
used as a pair to cancel each other out.

5
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

MODERN STREAM CIPHERS

In a modern stream cipher, encryption and decryption are done r bits at a time. We
have a plaintext bit stream P = pn...p2p1, a ciphertext bit stream C
=cn...c2c1, and a key bit stream K = kn...k2k1, in which pi, ci, and ki are r-bit
words.

Encryption is ci= E (ki, pi), and decryption is pi= D (ki, ci)

Stream ciphers are faster than block ciphers. The hardware implementation of a
stream cipher is also easier. When we need to encrypt binary streams and transmit
them at a constant rate, a stream cipher is the better choice to use. Stream ciphers
are also more immune to the corruption of bits during transmission.

In a modern stream cipher, each r-bit word in the plaintext stream is


enciphered using an r-bit word in the key stream to create the corresponding
r-bit word in the ciphertext stream.

Synchronous Stream Ciphers

In a synchronous stream cipher, the key stream is independent of the plaintext or


ciphertext stream. The key stream is generated and used with no relationship
between key bits and the plaintext or ciphertext bits.

In a synchronous stream cipher the key is independent of the plaintext or


ciphertext.

Nonsynchronous Stream Ciphers

In a nonsynchronous stream cipher, each key in the key stream depends on previous
plaintext or ciphertext.

6
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

In a nonsynchronous stream cipher, the key depends on either the plaintext or


ciphertext.

1) Data Encryption Standard (DES)

The Data Encryption Standard (DES) is a symmetric-key block cipher published by


the National Institute of Standards and Technology (NIST).

Overview

DES is a block cipher, as shown in Figure

At the encryption site, DES takes a 64-bit plaintext and creates a 64-bit ciphertext;
at the decryption site, DES takes a 64-bit ciphertext and creates a 64-bit block of
plaintext. The same 56-bit cipher key is used for both encryption and decryption.

We have mentioned that DES uses a 56-bit key. Actually, the initial key consists of
64 bits. However, before the DES process even starts, every 8th bit of the key is
discarded to produce a 56-bit key. That is bit positions 8, 16, 24, 32, 40, 48, 56, and
64 are discarded.

7
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

Thus, the discarding of every 8th bit of the key produces a 56-bit key from the
original 64-bit key.

DES STRUCTURE

The basic process in enciphering a 64-bit data block using the DES consists of:
● an initial permutation (IP)
● 16 rounds of a complex key dependent calculation f
● a final permutation, being the inverse of IP

Let us now discuss the broad-level steps in DES.


● Step1: In the first step, the 64-bit plain text block is handed over to an initial
Permutation (IP) function.

● Step2: The initial permutation is performed on plain text.

● Step3: Next, the initial permutation (IP) produces two halves of the permuted
block; saying Left Plain Text (LPT) and Right Plain Text (RPT).

● Step4: Now each LPT and RPT go through 16 rounds of the encryption process.

8
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

● Step5: In the end, LPT and RPT are rejoined and a Final Permutation (FP) is
performed on the combined block

● Step6: The result of this process produces 64-bit ciphertext.

Initial and Final Permutations

The initial and final permutations (P-boxes). Each of these permutations takes a
64-bit input and permutes them according to a predefined rule.

Below Figure shows only a few input ports and the corresponding output ports.

These permutations are keyless straight permutations that are the inverse of each
other.

For example, in the initial permutation, the 58th bit in the input becomes the first bit
in the output. Similarly, in the final permutation, the first bit in the input becomes
the 58th bit in the output.

Initial & Final Permutation Steps in DES:

9
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

Rounds

After IP is done, the resulting 64-bit permuted text block is divided into two half
blocks.
Each half-block consists of 32 bits, and each of the 16 rounds, in turn, consists
of the broad-level steps outlined in the figure.

Fig: Details of one round

Step-1: Key transformation:

The initial 64-bit key is transformed into a 56-bit key by discarding every 8th bit of
the initial key. Thus, for each a 56-bit key is available. From this 56-bit key, a
different 48-bit Sub Key is generated during each round using a process called key
transformation.
For this, the 56-bit key is divided into two halves, each of 28 bits. These halves are
circularly shifted left by one or two positions, depending on the round.
10
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

For example: if the round numbers 1, 2, 9, or 16 the shift is done by only one position for
other rounds, the circular shift is done by two positions.

After an appropriate shift, 48 of the 56 bits are selected. for selecting 48 of the 56
bits the table is shown in the figure given below. For instance, after the shift, bit
number 14 moves to the first position, bit number 17 moves to the second position,
and so on. If we observe the table carefully, we will realize that it contains only
48-bit positions. Bit number 18 is discarded (we will not find it in the table), like 7
others, to reduce a 56-bit key to a 48-bit key. Since the key transformation process
involves permutation as well as a selection of a 48-bit subset of the original 56-bit
key it is called Compression Permutation.

Step-2: Expansion Permutation:

After the initial permutation, we had two 32-bit plain text areas called Left Plain
Text(LPT) and Right Plain Text(RPT). During the expansion permutation, the RPT is
expanded from 32 bits to 48 bits. Bits are permuted as well hence called expansion
permutation. This happens as the 32-bit RPT is divided into 8 blocks, with each block
consisting of 4 bits. Then, each 4-bit block of the previous step is then expanded to a
corresponding 6-bit block, i.e., per 4-bit block, 2 more bits are added.

This process results in expansion as well as a permutation of the input bit while
creating output. the expansion permutation process expands the 32-bit RPT to 48-bits.

11
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

XOR: After the expansion permutation, DES uses the XOR operation on the expanded
right section and the round key.

Step 3: S Box substitution

The 48-bit data from the second operation is divided into eight 6-bit chunks, and each
chunk is fed into a box.
The result of each box is a 4-bit chunk; when these are combined the result is a 32-bit text.
The substitution in each box follows a pre-determined rule based on a 4-row by
16-column table.

For example: The input to S-box 1 is 100011. What is the output?

12
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

Solution: If we write the first and the sixth bits together, we get 11 in binary, which is 3 in
decimal. The remaining bits are 0001 in binary, which is 1 in decimal. We look for the
value in row 3, column 1.
The result is 12 in decimal, which in binary is 1100. So the input 100011 yields the output
1100.
4.P-Box Permutation (Straight Permutation): The last operation in the DES function is
a straight permutation with a 32-bit input and a 32-bit output.
The input/output relationship for this operation is shown in Table

5.XOR and Swap: We have been performing all the operations only on 32 bit RPT. The
LPT was untouched so far. At this time the LPT is XORed with the output produced by
P-Box permutations.
The result of this XOR operation will become the new RPT. The old RPT becomes the
new LPT, in the process of swapping.

13
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

DES Weaknesses
S-boxes:
1. In S-box , the last three output bits can be derived in the same way as the first
output bit by complementing some of the input bits.
2. Two specifically chosen inputs to an S-box array can create the same output.
3. It is possible to obtain the same output in a single round by changing bits in
only three neighboring S-boxes.
P-boxes:
1. It is not clear why the designers of DES used the initial and final
permutations; these have no security benefits.
2. In the expansion permutation (inside the function), the first and fourth bits of
every 4-bit series are repeated.
Key Size:
DES with a cipher key of 56 bits is not safe enough to be used comfortably.
Variations of DES:
One solution is to use double DES (2DES) with two keys (112 bits) or triple
DES with three keys (168 bits).
Double DES:

Double DES is an encryption approach which need two instance of DES on same plain
text. In both instances it uses multiple keys to encrypt the plain text. Both keys are
needed at the time of decryption.

14
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

The 64 bit plain text goes into first DES instance which than transformed into a 64 bit
middle text utilizing the first key and thus it goes to second DES instance which
provides 64 bit cipher text by utilizing second key.
Double DES is easy as it does that normal DES does. Double DES need two keys to
say K1 and K2 in this algorithm. It can implement DES on the original plain text using
K1 to receive the encrypted text in cryptography. Therefore, it again implements DES
on the encrypted text but this time with the other key K2 in this algorithm.
Triple DES:
In Triple DES, the plain text block P is first encrypted with a key K1 then encrypts
with a second key K2 and finally with a third key K3 where K1, K2, and K3 are
distinct from each other in this algorithm. This is Decryption is completed in reverse
order in this method. Hence, this algorithm is generally used in PGP and S/MIME in
cryptography.

15
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

2) AES(Advanced Encryption Standard):

In the AES encryption process. The cipher takes a plaintext block size of 128 bits, or 16
bytes. The key length can be 16, 24, or 32 bytes (128, 192, or 256 bits).
The algorithm is referred to as AES-128, AES-192, or AES-256, depending on the key
length.
The input to the encryption and decryption algorithms is a single 128-bit block. This block
is depicted as a 4 * 4 square matrix of bytes. This block is copied into the State array,
which is modified at each stage of encryption or decryption. After the final stage, State is
copied to an output matrix.

The key is expanded into an array of key schedule words. In our example the expansion
for the 128-bit key. Each word is four bytes, and the total key schedule is 44 words for the
128-bit key. Note that the ordering of bytes within a matrix is by column. So, for example,
the first four bytes of a 128-bit plaintext input to the encryption cipher occupy the first
column of the in matrix, the second four bytes occupy the second column, and so on.
Similarly, the first four bytes of the expanded key, which form a word, occupy the first
column of the w matrix.

The cipher consists of N rounds, where the number of rounds depends on the key length:
10 rounds for a 16-byte key, 12 rounds for a 24-byte key, and 14 rounds for a 32-byte key.
The first N - 1 rounds consist of four distinct transformation functions: SubBytes,
ShiftRows, MixColumns, and AddRoundKey. The final round contains only three
transformations, and there is a initial single transformation (AddRoundKey) before the
first round, which can be considered Round 0. Each transformation takes one or more 4 *
4 matrices as input and produces a 4 * 4 matrix as output.

16
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

AES encrypts and decrypts data blocks. A block in AES is a group of 128 bits.
However, a block can be represented as a row matrix of 16 bytes.

AES uses several rounds in which each round is made of several stages. Data block
is transformed from one stage to another. At the beginning and end of the cipher,
AES uses the term data block; before and after each stage, the data block is referred
to as a state.

17
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

Example: Changing plain text into state

● AES processes the entire data block as a single matrix during each round using
substitutions and permutation.
● The key that is provided as input is expanded into an array of forty-four 32-bit (words)
w[i]. Four distinct words (128 bits) serve as a round key for each round.
● For both encryption and decryption, the cipher begins with an AddRoundKey stage,
followed by nine rounds that each includes all four stages, followed by a tenth round of
three stages.

18
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

● Only the AddRoundKey stage makes use of the key. For this reason, the cipher begins
and ends with an AddRoundKey stage. Any other stage, applied at the beginning or
end, is reversible without knowledge of the key and so would add no security.

Four transformations used in AES: Substitute Bytes Transformation, ShiftRows


Transformation, MixColumns Transformation and AddRoundKey Transformation.

i) Substitute Bytes Transformation: The forward substitute byte transformation, called


SubBytes, is a simple table lookup. AES defines a 16 * 1n6 matrix of byte values, called
an S-box, that contains a permutation of all possible 256 8-bit values. Each individual byte
of State is mapped into a new byte in the following way: The leftmost 4 bits of the byte
are used as a row value and the rightmost 4 bits are used as a column value. These row
and column values serve as indexes into the S-box to select a unique 8-bit output value.
For example, the hexadecimal value {95} references row 9, column 5 of the S-box, which
contains the value {2A}. Accordingly, the value {95} is mapped into the value {2A}

Example of the SubBytes transformation:

ii) ShiftRows Transformation: The forward shift row transformation, called ShiftRows.
The first row of State is not altered. For the second row, a 1-byte circular left shift is
performed. For the third row, a 2-byte circular left shift is performed. For the fourth row, a
3-byte circular left shift is performed. The following is an example of ShiftRows.

19
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

iii) MixColumns Transformation: The forward mix column transformation, called


MixColumns, operates on each column individually. Each byte of a column is mapped
into a new value that is a function of all four bytes in that column. The transformation can
be defined by the following matrix multiplication on State:

An example of MixColumns:

iv) AddRoundKey Transformation: In the forward add round key transformation, called
AddRoundKey, the 128 bits of State are bitwise XORed with the 128 bits of the round
key. the operation is a columnwise operation between the 4 bytes of a State column and
one word of the round key.

example of AddRoundKey:

20
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

[cipher text]

● This is the final cipher text for this round. Depending on the key length you
repeat the above steps until you complete the round 10, after which you
receive the final cipher text.

Key Expansion Algorithm: The AES key expansion algorithm takes as input a four-word
(16-byte) key and produces a linear array of 44 words (176 bytes). This is sufficient to
provide a fourword round key for the initial AddRoundKey stage and each of the 10
rounds of the cipher. The pseudocode on the next page describes the expansion. The key is
copied into the first four words of the expanded key. The remainder of the expanded key is
filled in four words at a time. Each added word w[i] depends on the immediately
preceding word, w[i - 1], and the word four positions back, w[i - 4]. In three out of four
cases, a simple XOR is used. For a word whose position in the w array is a multiple of 4, a
more complex function is used. Using the symbol g to represent that complex function.
The function g consists of the following subfunctions.
● RotWord performs a one-byte circular left shift on a word. This means that an input
word [B0, B1, B2, B3] is transformed into [B1, B2, B3, B0].
● SubWord performs a byte substitution on each byte of its input word, using the S-box.
● The result of steps 1 and 2 is XORed with a round constant, Rcon[j].

21
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

KeyExpansion (byte key[16], word w[44])


{
word temp
for (i = 0; i < 4; i++)
w[i] = (key[4*i], key[4*i+1], key[4*i+2], key[4*i+3]);

for (i = 4; i < 44; i++)


{
temp = w[i - 1];
if (i mod 4 = 0) temp = SubWord (RotWord (temp))
⊕ Rcon[i/4];
w[i] = w[i-4] ⊕ temp
}
}

22
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

ANALYSIS OF AES
Brute-Force Attack
AES is definitely more secure than DES due to the larger-size key (128, 192, and
256 bits). Let us compare DES with 56-bit cipher key and AES with 128-bit
cipher key. For DES we need 256(ignoring the key complement issue) tests to
find the key; for AES we need 2128 tests to find the key. This means that if we
can break DES in t seconds, we need (272 × t) seconds to break AES. This
would be almost impossible.

Simplicity and Cost


The algorithms used in AES are so simple that they can be easily implemented
using cheap processors and a minimum amount of memory.

23
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

3) Blowfish:
Blowfish is an encryption technique designed by Bruce Schneier in 1993 as an
alternative to DES Encryption Technique.
It is significantly faster than DES and provides a good encryption rate with no
effective cryptanalysis technique found to date. It is one of the first, secure block
ciphers not subject to any patents and hence freely available for anyone to use.
It is symmetric block cipher algorithm.
1. blockSize: 64-bits

2. keySize: 32-bits to 448-bits variable size

3. number of rounds: 16

4. number of subkeys: 18 [P-array]

5. number of substitution boxes: 4 [each having 512 entries of 32-bits

each]

Sub-key Generation − Blowfish cryptographic algorithm uses huge number of sub


keys. These keys are creating earlier to any of the data encryption or the decryption.
The p-array includes 18, 32-bit sub keys − P1,P2,………….,P18.

Steps to Generate Sub Keys:

● Initialize first, the P-array with a fixed string .


For example , P1=0x243f6a88, P2=0x85a308d3, P3=0x13198a2e,
P4=0x3707344, etc.
● XOR P1 with the first 32 bits of the key, XOR P2 with second which is
32-bits of the key, etc. for all bits of the key (conceivably up to P14).
Repeatedly cycles the procedure through the key bits until the complete
P-array has been XORed with key bits.

24
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

Data Encryption −

Blowfish is a Feistel network including 16 rounds.


The input is a 64-bit data element.
Divide PT into two 32-bit halves : L, R.
Then, for i = 1 to 16;
L = L XOR Pi
R = F(L) XOR R

25
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

Swap L and R
After the 16th round,

Then, R = R XOR P17 and L = L XOR P18.


Finally, combine L and R to get the ciphertext.

Function F (4 S-Boxes)

26
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

4) RC4
RC4 is a stream cipher that was designed in 1984 by Ronald Rivest for RSA Data
Security.
RC4 is used in many data communication and networking protocols.
The RC4 algorithm is remarkably simple and quite easy to explain.
RC4 is a byte-oriented stream cipher in which a byte (8 bits) of a plaintext is
exclusive-ored (XOR) with a byte of key to produce a byte of a ciphertext.
The secret key, from which the one-byte keys in the key stream are generated, can
contain anywhere from 1 to 256 bytes.
State
RC4 is based on the concept of a state. At each moment, a state of 256 bytes is
active, from which one of the bytes is randomly selected to serve as the key for
encryption.
The idea can be shown as an array of bytes:
S[0], S[1] ,S[2], ... S[255]
Initialization:
To begin, the entries of S are set equal to the values from 0 through 255 in
ascending order; that is, S[0] = 0, S[1] = 1, S[255] = 255 . A temporary vector, T, is
also created. If the length of the key K is 256 bytes, then K is transferred to T.
Otherwise, for a key of length keylen bytes, the first keylen elements of T are
copied from K, and then K is repeated as many times as necessary to fill out T.

for (i = 0 to 255)
{
S[i] ← i
27
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

K[i] ← Key [i mod KeyLength]


}

In the first step, the state is initialized to values 0, 1, ..., 255. A key array, K[0],
K[1],..., K[255] is also created. If the secret key has exactly 256 bytes, the bytes are
copied to the K array; otherwise, the bytes are repeated until the K array is filled.

In the second step, the initialized state goes through a permutation (swapping the
elements) based on the value of the bytes in K[i]. The key byte is used only in this
step to define which elements are to be swapped. After this step, the state bytes are
completely shuffled.
j←0
for (i = 0 to 255)
{
j ← (j + S[i] + K[i]) mod 256
swap (S[i] , S[j])
}

28
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

RC4_Encryption Algorithm:
RC4_Encryption (K){
// Creation of initial state and key bytes
for (i = 0 to 255)
{
S[i] ← i
K[i] ← Key [i mod KeyLength]
}
// Permuting state bytes based on values of key bytes
j←0
for (i = 0 to 255)
{
j ← (j + S[i] + K[i]) mod 256
swap (S[i] , S[j])
}
// Continuously permuting state bytes, generating keys, and encrypting
i←0
j←0
while (more byte to encrypt)
{
i ← (i + 1) mod 256
j ← (j + S[i]) mod 256
swap (S [i] , S[j])
k ← S [(S[i] + S[j]) mod 256]
// Key is ready, encrypt
input P
C←P⊕k
output C
}}

29
Prof.Andleeb Sahar
UNIT II CRYPTOGRAPHY & NETWORK SECURITY

Key Distribution:
Symmetric cryptography refers to a type of cryptography whereby the key that is
used to encrypt the data is the same for decrypting the data, and thus it is also
known as a shared key cryptography.
The key must be established or agreed on before the data exchange between the
communicating parties. This is the reason it is also called secret key cryptography.
Keys can be distributed by any one of the following ways:
1. Sender can select the key and physically deliver it to receiver.
2. A trusted third party can select the key and physically deliver it to the sender and the
receiver.
3. If sender and receiver have previously and recently used a key, one party can
transmit the new key to the other, encrypted using the old key.
4. If sender and receiver each has an encrypted connection to a third party, then the
third party can deliver a key on the encrypted links to sender and receiver.

30
Prof.Andleeb Sahar

You might also like