It is difficult, perhaps impossible, to learn where the generator state resides in the too concise synopsis of RC4 function given here.
We expand here.
- r = (fileVal "RC4")
-
r is an immutable value that accesses the functionality as follows:
- s= (r op seed)
-
s is a mutable generator of pseudo random values.
seed is an ASCII string, in the sense of a Scheme string, which seeds the generator.
op is one of three scheme symbols the choice of which determines the form of the pseudo random values.
s remembers the op and carries the internal generator state.
- if op = 'nb
-
then (s n) yields the next pseudo random integer with 8n bits.
s is thereby mutated.
- if op = 'sb
-
then (s) yields the next 8 bit integer.
- if op = 'rbi
-
then s is immutable and remembers the constant seed.
Each invocation of s, as in gn = (s n) produces a mutable generator gn, successive invocations of which produce random non negative integers less than n.
The RC4 crypto plan is to produce the key-stream for seed s as follows:
(define t ((fileVal "RC4") 'sb s)).
The jth invocation of this value produces the jth character from the stream.
(list (t) (t) (t) … ) is then the key-stream.
Some advocate discarding the first 1000 stream values.
Here are my development notes for the code.