Professional Documents
Culture Documents
Report CCN
Report CCN
Report CCN
Presentation 10
Report 10
Viva 05
Total 40
REPORT VERIFICATION
Date :
Staff Name :
Signature :
Title of the project: Implementation of RC4 Encryption and Decryption Algorithms
Introduction: RC4 is a symmetric key stream cipher algorithm, which means it uses the
same key for both encryption and decryption, and operates on a stream of input data one byte
at a time. It was developed by Ron Rivest in 1987 and is widely used in various applications,
such as wireless security protocols (e.g., WEP and WPA), SSL/TLS, and file encryption.
RC4 works by initializing a state array (S) of 256 bytes, where each byte is a number from 0
to 255, and then performing a key-scheduling algorithm (KSA) that modifies the state array
based on the input key. After the KSA, the state array is used to generate a keystream of
pseudo-random bytes using a pseudo-random generation algorithm (PRGA). The keystream
is then XORed with the plaintext to produce the ciphertext, or XORed with the ciphertext to
recover the plaintext.
One of the strengths of RC4 is its simplicity and speed. It can be implemented with relatively
few lines of code and can process data quickly. However, RC4 has several weaknesses,
including biases in the initial bytes of the keystream, and a vulnerability to related key attacks
when the same key is used multiple times with different nonces. As a result, RC4 is generally
no longer considered secure for modern cryptography applications and is recommended to be
avoided in favor of newer algorithms such as AES
The KSA takes the encryption key and uses it to initialize an array of 256 bytes called the
state (S). It does this by performing a series of swaps between elements of S based on the key
and the current position in the array.
The PRGA generates the keystream by repeatedly swapping elements of S and using them to
compute a pseudo-random byte K. This process continues indefinitely, generating a stream of
pseudo-random bytes that are XORed with the plaintext to produce the ciphertext.
To encrypt a message using RC4, we first generate the keystream by running the KSA and
PRGA with the encryption key. We then XOR each byte of the plaintext with the
corresponding byte of the keystream to produce the ciphertext.
To decrypt a message, we simply encrypt the ciphertext using the same key. This is possible
because XORing a value twice with the same key will cancel out the encryption and return
the original plaintext.
Define the Key and Plaintext: To start with, we need to define the key and plaintext that we
want to encrypt using the RC4 algorithm.
Initialize the S-Box and Key Scheduling Algorithm (KSA): In the next step, we need to
initialize the S-box and perform the Key Scheduling Algorithm (KSA
Generate the Pseudo-Random Stream (PRGA): In the next step, we need to generate the
Pseudo-Random Stream using the S-box and the PRGA
Encrypt the Plaintext: In this step, we need to encrypt the plaintext using the Pseudo-Random
Stream.
To decrypt a message, we simply encrypt the ciphertext using the same key. This is possible
because XORing a value twice with the same key will cancel out the encryption and return
the original plaintext.
Programme:
def encryption():
print(" ")
for i in range(len(pt)):
pt[i] = int(pt[i], 2)
if diff != 0:
for i in range(0, diff):
key_list.append(key_list[i])
# Print S
print(S)
initial_permutation_array = S
print(" ")
print("The initial permutation array is : ",
initial_permutation_array)
N = len(S)
i = j = 0
global key_stream
key_stream = []
XOR()
print(" ")
print("Cipher text : ", encrypted_to_bits)
encryption()
print("---------------------------------------------------------")
for i in range(len(pt)):
pt[i] = int(pt[i], 2)
if diff != 0:
for i in range(0, diff):
key_list.append(key_list[i])
print(" ")
# KSA algorithm
def KSA():
j = 0
N = len(S)
initial_permutation_array = S
print(" ")
print("The initial permutation array is : ",
initial_permutation_array)
print("KSA iterations : ")
print(" ")
KSA()
print(" ")
N = len(S)
i = j = 0
global key_stream
key_stream = []
do_XOR()
print(" ")
print("Decrypted text : ",
decrypted_to_bits)
# Driver Code
decryption()
To decrypt the ciphertext, you can use the same key to generate the keystream and then
XOR it with the ciphertext to recover the original plaintext. The implementation of RC4
encryption and decryption in Python is relatively simple and can be done with just a few lines
of code
Tabulation: Key: 101001000001
S.No Plain text Cipher Text
1 101001000001 110011100011
2 101001000001 011011100011
3 101001000001 010011100011
4 111010010010 000011100011
5 001110001110 110111111111
Conclusion:
In conclusion, RC4 is a widely used symmetric key stream cipher algorithm for encryption
and decryption of data. Although RC4 is simple and fast, it has several weaknesses that make
it insecure for modern cryptography applications. These include biases in the initial bytes of
the keystream and vulnerability to related key attacks. As a result, RC4 is no longer
recommended for use in new applications and is generally considered to be insecure. It is
recommended to use newer, more secure encrpyption algorithms such as AES for
cryptography applications.