View Single Post
Old 01-09-2005, 10:59 PM   #1 (permalink)
Spook
Registered User
 
Join Date: Mar 2004
Posts: 9
Spook is on a distinguished road
Send a message via ICQ to Spook Send a message via AIM to Spook Send a message via Yahoo to Spook
problem implementing RC4/ciphersaber 2

After some meddling with my code and finally getting ciphersaber-1 to work, i thought it would be fairly simple to implement version 2. According the the webpage, one just has to add another loop around the key mixing phase. Excerpts follow :
Code:
i = j = 0; /* i and j are unsigned chars, as are all bytes in state[] and state2[] */
do {
	j = ( j + state[i] + state2[i] );
	x = state[i];
	state[i] = state[j];
	state[j] = x;
	i++;
} while (i);
The above works flawlessly on the test vectors on the site. Now, supposedly to use the improved version, one just needs to add a loop around they key mixing loop shown above.
Code:
/* n is a straight up integer */
i = j = 0;
while(n) {
	do {
		j = ( j + state[i] + state2[i] );
		x = state[i];
		state[i] = state[j];
		state[j] = x;
		i++;
	} while (i);
	n--;
}
However, the test vector, when decoded with the key "asdfg" and N=10 produces gibberish. Is there some flaw in the way I've set these loops up that I'm simply missing?

Ciphersaber Home page if this helps...

Thanks,
Spook

Last edited by redhead; 01-09-2005 at 11:56 PM. Reason: Added correct use of [url ] [/url ] tags
Spook is offline   Reply With Quote