The Key Scheduling Algorithm is the first part of the encryption process. The following is the algorithm actually used in RC4 by line with an explanation for each line.
1. Assume N = 256 2. K = Secrete Key array 3. Initialization: 4. For i = 0 to N 1 5. S[i] = i 6. j = 0 7. Scrambling: 8. For i = 0 ... N 1 9. j = j + S[i] + K[i] 10. Swap(S[i], S[j])
N is an index value. It determines how strong the scrambling process is. WEP uses a value of 256.
K is the letter used to symbolize the secret key array. In the case of a five-character, pre-shared key, this value would be the three-character IV + five-character pre-shared key ‡ eight-character secret key. Each character is held in the corresponding K position. This value does not get scrambled.
This starts the initialization of the KSA. It basically is used to seed the empty State (S) array with values 0255.
This is the start of the loop process that increases the value of i each time the algorithm loops.
Once it is done, the S array will hold values 0255 in corresponding array position 0255.
j is used to hold a value during the scrambling process, but it must first be initialized to ensure that it always starts at 0.
This starts the scrambling process that creates the psuedo random S array from the previously seeded S array.
Another loop that ensures the scrambling process occurs 256 times.
This is the equation used to merge the properties of the secret key with the state array (S) to create a psuedo random number, which is assigned to j.
Finally, a swap function is performed to swap the value held in S[i] with the value held in S[j].
As you can see, this is not a terribly complex process. Some simple math based on the secret key, and you have a psuedo random state array. The next part takes this array and creates a stream of data that is used to encrypt the data to be sent over the airwaves.