QT Lock / Key verification

Technical discussion about the NMDC and <a href="http://dcpp.net/ADC.html">ADC</A> protocol. The NMDC protocol is documented in the <a href="http://dcpp.net/wiki/">Wiki</a>, so feel free to refer to it.

Moderator: Moderators

Locked
MMayfield45
Posts: 3
Joined: 2005-12-03 11:27

QT Lock / Key verification

Post by MMayfield45 » 2005-12-03 11:29

I have been trying to connect to a YnHub with C++ and QT. i managed to put together a function to turn the lock into a key, when i send it to the server it complains about the key being incorrect. Where have i gone wrong?

Code: Select all

QByteArray Client::lockToKey(QByteArray lock)
{
    QByteArray key;
    
    int i;
    
    for (i = 1; i < lock.length(); i++)
        key[i] = lock[i] xor lock[i-1];
        
    key[0] = lock[0]  xor lock[lock.size()-1]  xor lock[lock.length()-2] xor 5;
    
    
    for (i = 0; i < lock.size(); i++)
        key[i] = ((key[i]<<4) & 240) | ((key[i]>>4) & 15);

    QByteArray finalKey;
    
    QByteArray ba;
    ba.resize(6);
    ba[0] = 0x00;
    ba[1] = 0x05;
    ba[2] = 0x24;
    ba[3] = 0x60;
    ba[4] = 0x7C;
    ba[5] = 0x7F;
        
    for (i = 0; i < key.size(); i++)
    {
        
        if (key[i] == ba[0]){
            finalKey.append("/%DCN000%/");
        }else if (key[i] == ba[1]){
            finalKey.append("/%DCN005%/");
        }else if (key[i] == ba[2]){
            finalKey.append("/%DCN036%/");
        }else if (key[i] == ba[3]){
            finalKey.append("/%DCN096%/");
        }else if (key[i] == ba[4]){
            finalKey.append("/%DCN124%/");
        }else if (key[i] == ba[5]){
            finalKey.append("/%DCN126%/");
        }else{
            finalKey.append(key[i]);
        }
    }
    
    return finalKey;
}

cologic
Programmer
Posts: 337
Joined: 2003-01-06 13:32
Contact:

Post by cologic » 2005-12-03 11:52

This wiki page provides guidance, if you've not seen it.

MMayfield45
Posts: 3
Joined: 2005-12-03 11:27

Post by MMayfield45 » 2005-12-03 12:09

thanks, i have seen that, hence that is how i came up with the code.

Look below. The top key is correct, the bottom is what my script came up with. Where am i going wrong.

Code: Select all

$Key tÑÀ° A ѱ±ÀÀ07‡Ã°GB’!/%DCN096%//%DCN000%/€Ã

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

Post by joakim_tosteberg » 2005-12-04 06:59

The code looks good from a quick look, what first comes to my mind is that it could be some kind of encoding problem.
How is a QByteArray defined?

Pothead
Posts: 223
Joined: 2005-01-15 06:55

Post by Pothead » 2005-12-04 09:23

Since it's replacing a few characters with ? are you sure you using right encoding or whatever.
‡ ’ € —

Are the ones it doesn't seem to be doing properly.

bastya_elvtars
Posts: 164
Joined: 2005-01-06 08:39
Location: HU
Contact:

Post by bastya_elvtars » 2005-12-04 09:34

As far as I know (from my early KDE times), Qt has problems with certain characters, especially ő and ű which are way important in Hungary. :)
Hey you, / Don't help them to bury the light... / Don't give in / Without a fight. (Pink Floyd)

MMayfield45
Posts: 3
Joined: 2005-12-03 11:27

Post by MMayfield45 » 2005-12-05 06:13

Sorry nothing to do with the question marks, found out why: 0x7F is not 126

Locked