grinding my teeth on this lock to key problem

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
tridde
Posts: 1
Joined: 2003-02-08 12:15

grinding my teeth on this lock to key problem

Post by tridde » 2003-02-08 12:21

I've been trying to convert a lock to a key by using the protocol spec on http://wza.digitalbrains.com/DC/doc/Appendix_A.html

but i've had no luck ;( (the code is orignally borrowed/stolen but I have the credits in the sourcefile)

Can anyone help me to crack this nut, what am I doing wrong?

Code: Select all

 static String decode(String lock, byte xorKey)
    {
      StringBuffer key = new StringBuffer();

      int lockLength = lock.length();

      System.out.println(lockLength);

      // The first byte is handled separately from the first, last,
      // and second to last bytes.
      char a1 = (char)lock.charAt(0);
      char a2 = (char)lock.charAt(lockLength - 1);
      char a3 = (char)lock.charAt(lockLength - 2);

      // Xor them all and swap nibbles.
      //char char1 = (char) (a1 ^ xorKey);

      for(int i = 1; i < lockLength;i++ )
      {
          key.append((char)(lock.charAt(i) ^ lock.charAt(i-1))  );
      }

      int char1 = a1 ^ a2 ^ a3 ^5;
      key.insert(0,(char)char1);

      // And do the rest of the bytes.
      for (int i = 0; i < lockLength; i++)
      {
	// Each key byte is the xor of the corresponding lock byte
	// and the one before it, nibble-swapped (that's why the
	// first is special).
	        char a5 = (char)key.charAt(i);
	//char a6 = (char)key.charAt(i-1);

	//char char3 = (char) (a5 ^ a6);
	        char char4 = (char)((a5 << 4) & 240 | (a5 >> 4)  & 15);

	        key.append((char)char4);
      }

      // Key has the right bytes, but it needs to have certain
      // characters escaped.
      return escapeChars(key);
    }


  static String escapeChars(StringBuffer key)
    {
      StringBuffer encoded = new StringBuffer();

      for (int i = 0; i  < key.length(); i++)
      {
	// You might think we'd have to add the '/' escape character
	// to this list.  Oh well.
	int a = (int)key.charAt(i);
	if (a == 126 || // '~'
	    a == 124 || // '|'
	    a == 96 ||  // '`'
	    a == 36 ||  // '$'
	    a == 5 ||   // '^E'
	    a == 0)     // NUL
	{
	  encoded.append("/%DCN");
	  // Ensure we have 3 digits.
	  if (a < 100)
	    encoded.append("0");
	  if (a < 10)
	    encoded.append("0");
	  encoded.append(a); // As a string integer
	  encoded.append("%/");
	} else {
	  encoded.append((char)a);  // No transformation.
	}
      }

      return encoded.toString();
    }

smitty
Posts: 53
Joined: 2003-03-01 14:45

Post by smitty » 2003-03-06 00:05

read the "key" post

Sedulus
Forum Moderator
Posts: 687
Joined: 2003-01-04 09:32
Contact:

Post by Sedulus » 2003-03-06 06:30

this is from the Shasta hub right?
his version should work.. why modify it?
perhaps you are having a problem related to character encoding (i.e. unicode instead of plain ascii)
http://dc.selwerd.nl/hublist.xml.bz2
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)

Locked