This repository contains a C++ implementation of the RC4 encryption algorithm along with several tests to explore weaknesses in the algorithm. RC4 is a symmetric key stream cipher widely used in various cryptographic applications.
The RC4 Encryption Algorithm is a widely used symmetric key stream cipher known for its simplicity and efficiency. This implementation includes functions to set a custom 128-bit key, generate a random key, and perform tests to identify potential weaknesses in the algorithm.
-
Test 1: Probability of Second Byte Being Zero This test calculates the probability of generating two bytes with the second byte being zero. It performs the test for a specified number of generations and compares the result to the expected probability.
-
Test 2: Probability of Two Consecutive Zero Bytes This test evaluates the probability of generating two consecutive zero bytes. It conducts the test for different numbers of generations and compares the results to the expected probabilities.
-
Test 3: Related Key Attack and Hamming Distance This test demonstrates a related key attack on the RC4 encryption algorithm. It generates two related 128-bit keys, initializes RC4 internal states using the key-scheduling algorithm (KSA), and calculates the Hamming distance between the two internal states to measure their difference.