<VS2005 Lock2Key>
Moderator: Moderators
<VS2005 Lock2Key>
Hello
Could somebody show me a working lock2key function for Visual Basic 2005 ? I have compiled some vb 2003 opensource bots, but the lock2key doesnt work . Is there a change in system.encoding.default in .net frmwrk 2.0 ?
THX
Could somebody show me a working lock2key function for Visual Basic 2005 ? I have compiled some vb 2003 opensource bots, but the lock2key doesnt work . Is there a change in system.encoding.default in .net frmwrk 2.0 ?
THX
-
- Forum Moderator
- Posts: 1420
- Joined: 2003-04-22 14:37
http://www.dcpp.net/wiki/index.php/LockToKey
Check the above link for examples in a number of languages.
Check the above link for examples in a number of languages.
-
- Posts: 164
- Joined: 2005-01-06 08:39
- Location: HU
- Contact:
Re: <VS2005 Lock2Key>
StormDev wrote:Visual Basic 2005
Hey you, / Don't help them to bury the light... / Don't give in / Without a fight. (Pink Floyd)
Re: <VS2005 Lock2Key>
UPS...bastya_elvtars wrote:StormDev wrote:Visual Basic 2005
Here's mine For vb.net 2005 thanks todi and tasman for providing initial code...
Code: Select all
' Fixed the one from chimera source to work in strict
'New Lock -> Key function borrowed from the ShadowDC client
'and adapted to VB.NET with the help of Tasman (Thanks!)
Private Function LockToKey(ByVal strLock As String, ByVal n As Integer) As String
Dim h As Integer
Dim ub As Integer
'n = 5 for hub and client locks
h = strLock.IndexOf(" Pk=")
If h > 0 Then
strLock = strLock.Substring(0, h)
End If
'The lock only continues to the first space (Pk= comes after)
'Make sure it is more than 3 characters
If strLock.Length > 3 Then
ub = strLock.Length - 1
'The first character is handled differently from the others
'h = Asc(strLock) Xor Asc(strLock.Chars(ub)) Xor Asc(strLock.Chars(ub - 1)) Xor n
h = Asc(strLock.Chars(0)) Xor Asc(strLock.Chars(ub)) Xor Asc(strLock.Chars(ub - 1)) Xor n
h = ((h * 16) And 240) Or ((h \ 16) And 15)
'Equivalent of bit shifting four to the left (* 2^4) and four to the right (\ 2^4)
'Check for illegal characters
Select Case h
Case 0, 5, 36, 96, 124, 126
LockToKey = "/%DCN" & StrReverse(StrReverse("00" & h).Substring(0, 3)) & "%/"
'LockToKey = "/%DCN" & Right$("00" & h, 3) & "%/"
Case Else
LockToKey = Chr(h)
End Select
'Now the rest of the characaters in the lock are handled the same
For n = 1 To ub
h = Asc(strLock.Chars(n)) Xor Asc(strLock.Chars(n - 1))
h = ((h * 16) And 240) Or ((h \ 16) And 15)
Select Case h
Case 0, 5, 36, 96, 124, 126
LockToKey = LockToKey & "/%DCN" & StrReverse(StrReverse("00" & h).Substring(0, 3)) & "%/"
Case Else
LockToKey = LockToKey & Chr(h)
End Select
Next
Else
LockToKey = "Lock string length must be greater than 3 characters."
End If
Exit Function
<random funny comment>
Here is an example on how to use the lock2key function posted above:
Please take note that all encoding is Default 'System.Text.Encoding.Default'
Please take note that all encoding is Default 'System.Text.Encoding.Default'
Code: Select all
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' This is a routine to test a lock2key function
Dim Socket As New System.Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
' Connect to server
Socket.Connect("dope-shit.420net.org", 420)
' Wait for data
Dim bInput(1024) As Byte
Dim iBytesIn As Integer = Socket.Receive(bInput)
' Check for disconnection
If iBytesIn = 0 Then
MsgBox("Disconnected")
End If
' Encode data to string
Dim sPackets As String = System.Text.Encoding.Default.GetString(bInput, 0, iBytesIn)
' Split data into packets
Dim arPackets() As String = Split(sPackets, "|")
' Loop through packets
Dim iPacketCount As Integer = 0
For iPacketCount = 0 To arPackets.Length - 2
' Get the packet from the array
Dim sData As String = arPackets(iPacketCount)
' Split the packet into a command array for interpreting
Dim arCommand() As String = Split(sData, " ", 2)
MsgBox(sData)
' Do action on command
Select Case arCommand(0)
Case "$Lock"
' Make key output buffer
Dim bOutput() As Byte
bOutput = System.Text.Encoding.Default.GetBytes("$Key " & Me.LockToKey(arCommand(1)) & "|")
' Send key through socket
Socket.Send(bOutput)
' Get next data
iBytesIn = Socket.Receive(bInput)
' Check for disconnection
If iBytesIn = 0 Then
MsgBox("Disconnected")
Else
MsgBox(System.Text.Encoding.ASCII.GetString(bInput, 0, iBytesIn))
End If
End Select
Next
' Close the socket
Socket.Close()
Socket = Nothing
sPackets = Nothing
arPackets = Nothing
bInput = Nothing
End Sub
Private Function LockToKey(ByVal strLock As String, Optional ByVal n As Integer = 5) As String
Dim h As Integer
Dim ub As Integer
'n = 5 for hub and client locks
h = strLock.IndexOf(" Pk=")
If h > 0 Then
strLock = strLock.Substring(0, h)
End If
'The lock only continues to the first space (Pk= comes after)
'Make sure it is more than 3 characters
If strLock.Length > 3 Then
ub = strLock.Length - 1
'The first character is handled differently from the others
'h = Asc(strLock) Xor Asc(strLock.Chars(ub)) Xor Asc(strLock.Chars(ub - 1)) Xor n
h = Asc(strLock.Chars(0)) Xor Asc(strLock.Chars(ub)) Xor Asc(strLock.Chars(ub - 1)) Xor n
h = ((h * 16) And 240) Or ((h \ 16) And 15)
'Equivalent of bit shifting four to the left (* 2^4) and four to the right (\ 2^4)
'Check for illegal characters
Select Case h
Case 0, 5, 36, 96, 124, 126
LockToKey = "/%DCN" & StrReverse(StrReverse("00" & h).Substring(0, 3)) & "%/"
'LockToKey = "/%DCN" & Right$("00" & h, 3) & "%/"
Case Else
LockToKey = Chr(h)
End Select
'Now the rest of the characaters in the lock are handled the same
For n = 1 To ub
h = Asc(strLock.Chars(n)) Xor Asc(strLock.Chars(n - 1))
h = ((h * 16) And 240) Or ((h \ 16) And 15)
Select Case h
Case 0, 5, 36, 96, 124, 126
LockToKey = LockToKey & "/%DCN" & StrReverse(StrReverse("00" & h).Substring(0, 3)) & "%/"
Case Else
LockToKey = LockToKey & Chr(h)
End Select
Next
Else
LockToKey = "Lock string length must be greater than 3 characters."
End If
Exit Function
End Function
End Class
Well, i done a little app with that code i posted before so you can test ur encoding or even find what encoding you need to use.
I want you to try using the Default encoding (Leave checkbox checked) and if this doesnt work, please reply here telling us so.
download
If you find some encoding that works, this is how you implement it:
Also tell us the name of the encoding you might find that works.
Cheers
I want you to try using the Default encoding (Leave checkbox checked) and if this doesnt work, please reply here telling us so.
download
If you find some encoding that works, this is how you implement it:
Code: Select all
Dim Encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding(sEncodingName)
Cheers
I just found some encoding that works
Windows-1252
Windows-1254
Usage for both encoding types:
Windows-1252
Windows-1254
Usage for both encoding types:
Code: Select all
Dim Encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("Windows-1252")
Code: Select all
Dim Encoding As System.Text.Encoding = System.Text.Encoding.GetEncoding("Windows-1254")
-
- Forum Moderator
- Posts: 587
- Joined: 2003-05-07 02:38
- Location: Sweden, Linkoping