[Mono-devel-list] Re: Can you help me in this conversion from VB to C# ?

Alessandro Torrisi alessandro.torrisi at eurone.it
Wed Sep 22 10:03:30 EDT 2004


Hi ! I modified my function but still nothing....I report my function in C# 
and the correct code in VB.NET wich make me login in a Direct Connect Server 
(DC Hub). I want to do a multiplatform CLIENT step-by-step little-by-little 
but the this key is for me difficult to translate...please help me !

I'm worried about array indexes or functions...

-----------------------------------------------------------------------------------------------------------------------------

public static string LockToKey(string Lock) {
  string ret;
  int h, j, n;
  n = 5;
  
  h = Lock.IndexOf(" ");
  if (h!=-1) {
   Lock = Lock.Substring(0,h-1);
  }
  
  h = Lock.ToCharArray()[0] ^ Lock.ToCharArray()[Lock.Length-1] ^ 
Lock.ToCharArray()[Lock.Length-2] ^ n;
  h = (h/16) ^ (h*16);
  
  h %= 255;
  
  switch (h) {
   case 0:
    ret = "/%DCN000%/";
    break;
   case 5:
    ret = "/%DCN005%/";
    break;
   case 36:
    ret = "/%DCN036%/";
    break;
   case 96:
    ret = "/%DCN096%/";
    break;
   case 124:
    ret = "/%DCN124%/";
    break;
   case 126:
    ret = "/%DCN126%/";
    break;
   default:
    ret = Convert.ToString((char)h);
    break;
  }
  
  for (j=1;j<Lock.Length;j++) {
   h = Lock.ToCharArray()[j] ^ Lock.ToCharArray()[j-1];
   h = (h/16) ^ (h*16);
   
   h %= 255;
   
   switch (h) {
    case 0:
     ret = ret + "/%DCN000%/";
     break;
    case 5:
     ret = ret + "/%DCN005%/";
     break;
    case 36:
     ret = ret + "/%DCN036%/";
     break;
    case 96:
     ret = ret + "/%DCN096%/";
     break;
    case 124:
     ret = ret + "/%DCN124%/";
     break;
    case 126:
     ret = ret + "/%DCN126%/";
     break;
    default:
     ret = ret + Convert.ToString((char)h);
     break;
   }
   
   
  }
   
  return ret;
 }

_________________________________________________________________

Public Function LockToKey(ByVal Lck As String) As String
        Dim h As Integer, j As Integer, n As Integer
        n = 5

        h = InStr(1, Lck, " ")
        If h Then Lck = Left$(Lck, h - 1)

        h = Asc(Lck) Xor Asc(Right$(Lck, 1)) Xor Asc(Right$(Lck, 2)) Xor n
        h = (h \ 16) Xor (h * 16)

        Do While h > 255
            h = h - 256
        Loop

        Select Case h
            Case 0, 5, 36, 96, 124, 126
                LockToKey = "/%DCN" & Right$("00" & CStr(h), 3) & "%/"
            Case Else
                LockToKey = Chr(h)
        End Select

        For j = 2 To Len(Lck)
            h = Asc(Mid$(Lck, j, 1)) Xor Asc(Mid$(Lck, j - 1, 1))
            h = (h \ 16) Xor (h * 16)

            Do While h > 255
                h = h - 256
            Loop

            Select Case h
                Case 0, 5, 36, 96, 124, 126
                    LockToKey = LockToKey & "/%DCN" & Right$("00" & CStr(h), 
3) & "%/"
                Case Else
                    LockToKey = LockToKey & Chr(h)
            End Select
        Next
    End Function

________________________________________________________________

I report the documentation link
http://dcplusplus.sourceforge.net/wiki/index.php/LockToKey

Thanks in advance...bye



More information about the Mono-devel-list mailing list