Newbie Needs some help with lock to key conv.

Problems compiling? Don't understand the source code? Don't know how to code your feature? Post here.

Moderator: Moderators

Locked
Frizzle_Fry
Posts: 3
Joined: 2004-07-18 16:52

Newbie Needs some help with lock to key conv.

Post by Frizzle_Fry » 2004-07-18 16:59

I'm new to the concepts used in the lock and key conversion.. Ive read all that i possibly can on it, though Im still messing it up in my code... I dont know why, maybe someone can help me fix the problem I'm having.

Code: Select all


bool f_Special(int code)
{
	switch(code)
	{
	case 0:	case 5:	case 36: case 96: case 124: case 126:
		return true;
		break;
	default:
		return false;
	}
}
Just use that check to see if there are special characters or not. In the next part of the code, it is after I've already broken apart the string value returned from the hub. I broke apart the $lock and pk= using strtok().

Code: Select all

char *sendBack = new char[keyLen];

			for(int i = 1; i < keyLen; i++)	sendBack[i] = lock[i] ^ lock[i-1];
			sendBack[0] = lock[0] ^ lock[keyLen-1] ^ lock[keyLen-2];
			for(i = 0; i < keyLen; i++)	sendBack[i] = ((sendBack[i]<<4) & 240) | ((sendBack[i]>>4) & 15);			

			int j = 0;

			int count = 0;

			for(i = 0; i < keyLen; i++)
			{
				if(f_Special((int)sendBack[i]))
				{
					count++;
				}
			}

			char *temp = new char[keyLen + (count*9)];
			

			for(i = 0; i < keyLen; i++)
			{
			if(f_Special((int)sendBack[i]))
			{
				temp[j++] = '/'; temp[j++] = '%'; temp[j++] = 'D'; temp[j++] = 'C'; temp[j++] = 'N';

				switch((int)sendBack[i])
				{
				case 0: temp[j++] = '0'; temp[j++] = '0'; temp[j++] = '0'; break;
				case 5: temp[j++] = '0'; temp[j++] = '0'; temp[j++] = '5'; break;
				case 36: temp[j++] = '0'; temp[j++] = '3'; temp[j++] = '6'; break;
				case 96: temp[j++] = '0'; temp[j++] = '9'; temp[j++] = '6'; break;
				case 124: temp[j++] = '1'; temp[j++] = '2'; temp[j++] = '4'; break;
				case 126: temp[j++] = '1'; temp[j++] = '2'; temp[j++] = '6'; break;
				}
				temp[j++] = '%'; temp[j++] = '/'; 
							
			} else {
				temp[j++] = sendBack[i];
			}
			
		} 
		
			sprintf(buffer, "$Key %s|", temp);
after I put it altogether, it seems to work fine converting the special characters. Though When I try to connect to a hub, it disconnects me. I figure the key value I'm sending back is incorrect some how..

Sorry to ask about this, i know there is documentation on the website already. I'm just stumped with my own code. Well, anyone that manages to break that down for me thanks in advance! Sorry if the code seems kinda sloppy, hadnt had a chance to go through it yet.

TheParanoidOne
Forum Moderator
Posts: 1420
Joined: 2003-04-22 14:37

Post by TheParanoidOne » 2004-07-18 17:43

Have you looked at the following wiki page?

http://dcplusplus.sourceforge.net/wiki/ ... /LockToKey
The world is coming to an end. Please log off.

DC++ Guide | Words

PseudonympH
Forum Moderator
Posts: 366
Joined: 2004-03-06 02:46

Post by PseudonympH » 2004-07-18 22:13

you might want to use

Code: Select all

sprintf( temp+j, "/%%DCN%03d%%/", (int)sendback[i] );
j+=10;
instead of that nasty switch...

Frizzle_Fry
Posts: 3
Joined: 2004-07-18 16:52

Post by Frizzle_Fry » 2004-07-19 09:10

Thanks for your help guys, I found my mistake after looking through my code a few more times. Stupid me.

Frizzle_Fry
Posts: 3
Joined: 2004-07-18 16:52

Post by Frizzle_Fry » 2004-07-22 23:17

I have a couple quick questions.. I was wondering in which order I should be sending commands to the hub. Should I start with $MyNick <nick> Im trying to figure out which is the best way. When i try this with YHub, it doesnt send back anything right away, but with pTokaX it sends back a $Lock after that. Is there any standard for the order of operations to logging on?

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2004-07-22 23:44

See what DC++ does. Then try other clients such as DCGUI, DC:Pro, and NMDC 2.x/1.x.

joakim_tosteberg
Forum Moderator
Posts: 587
Joined: 2003-05-07 02:38
Location: Sweden, Linkoping

Post by joakim_tosteberg » 2004-07-24 04:35

There client<->hub login is documented at http://wza.digitalbrains.com/DC/doc/Cli ... Login.html

Toodles
Posts: 4
Joined: 2004-07-30 14:12
Contact:

Post by Toodles » 2004-08-14 12:52

OK I'm having a bit of a problem too with the lock to key!
Digital brains has been down for quite some time now and I know they have good information such as the equations needed and explains why and such.
The dc++ wiki page with locktokey has buggy and complicated past what it needs to be source for C++.

I tried using it and I've completeely changed it to fix all the bugs and such and I have been fixing runtime errors I've been getting with it left and right. Now I am getting one that links to internals and I don't know how to fix...

Anyone have a good link with locktokey info or can you tell me the equations or anything?

Thx!

GargoyleMT
DC++ Contributor
Posts: 3212
Joined: 2003-01-07 21:46
Location: .pa.us

Post by GargoyleMT » 2004-08-15 10:00

Toodles wrote:I tried using it and I've completeely changed it to fix all the bugs and such and I have been fixing runtime errors I've been getting with it left and right.
If the example in the wiki is broken, you can edit the page and contribute your (fixed) version.

Locked