Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
RC4
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Pseudo-random generation algorithm (PRGA)=== [[Image:RC4.svg|right|thumbnail|320px|The lookup stage of RC4. The output byte is selected by looking up the values of {{mono|S[i]}} and {{mono|S[j]}}, adding them together modulo 256, and then using the sum as an index into {{mono|S}}; {{mono|S(S[i] + S[j])}} is used as a byte of the key stream K.]] For as many iterations as are needed, the PRGA modifies the state and outputs a byte of the keystream. In each iteration, the PRGA: * increments {{mono|''i''}}; * looks up the {{mono|''i''}}th element of {{mono|S}}, {{mono|S[''i'']}}, and adds that to {{mono|''j''}}; * exchanges the values of {{mono|S[''i'']}} and {{mono|S[''j'']}}, then uses the sum {{mono|S[''i''] + S[''j''] (modulo 256)}} as an index to fetch a third element of {{mono|S}} (the keystream value {{mono|K}} below); * then bitwise exclusive ORed ([[Exclusive or|XOR]]ed) with the next byte of the message to produce the next byte of either ciphertext or plaintext. Each element of S is swapped with another element at least once every 256 iterations. i := 0 j := 0 '''while''' GeneratingOutput: i := (i + 1) mod 256 j := (j + S[i]) mod 256 [[Swap (computer science)|swap values]] of S[i] and S[j] t := (S[i] + S[j]) mod 256 K := S[t] output K '''endwhile''' Thus, this produces a stream of {{mono|K[0], K[1], ...}} which are [[Exclusive or|XOR]]ed with the {{mono|''plaintext''}} to obtain the {{mono|''ciphertext''}}. So {{mono|ciphertext[''l''] {{=}} plaintext[''l''] β K[''l'']}}.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)