Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 01-09-2005, 09: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 10:56 PM. Reason: Added correct use of [url ] [/url ] tags
Spook is offline   Reply With Quote
Old 01-09-2005, 11:01 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,710
redhead is on a distinguished road
Your 'i' will only have a value of 0, the first time the outer loop is run, in the example on the page, it is initiated to 0 on each run.
Code:
/* n is a straight up integer */
j = 0;
while(n) {
      i = 0;
      do {
            j = ( j + state[i] + state2[i] );
            x = state[i];
            state[i] = state[j];
            state[j] = x;
            i++;
      } while (i);
      n--;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 01-10-2005, 01:48 AM   #3 (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
I tried your fix and got the exact same results in the output file; the condition while(i) at the bottom of the do loop only fails when i is equal to 0, so each pass of the inner loop ranges from 0..255 each time (remembering that i is an unsigned char).
Spook is offline   Reply With Quote
Old 01-10-2005, 03:25 AM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Give the rest of the code then.
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
looping problem maria_arif MS Technologies ( ASP, VB, C#, .NET ) 1 11-29-2004 08:07 AM
JavaScript Problem dawkim HTML, XML, Javascript, AJAX 2 01-26-2004 07:02 PM
strange posting problem on my website......... trevor PHP 2 12-19-2003 12:25 PM
Help debugging a power problem Belisarius Lounge 0 10-25-2003 04:44 PM
This is a windows/C problem UnderWing Standard C, C++ 6 03-28-2003 06:17 AM


All times are GMT -8. The time now is 08:02 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting