2012-11-20 38 views
1

林基本上是试图实现这一目标:how to get the peers from an torrent tracker翻译十六进制值Vb.net [对于洪流跟踪器]

林卡住位置:

不仅如此,你必须发送的实际值该散列作为GET参数。 “76a36f1d11c72eb5663eeb4cf31e351321efa3a3”是散列的十六进制表示,但跟踪器协议指定您需要发送散列值(= bytestring)。因此,您必须首先解码十六进制表示,然后对其进行URL编码:urllib.urlencode([('info_hash','76a36f1d11c72eb5663eeb4cf31e351321efa3a3'.decode('hex'))])=='info_hash = v%A3o%1D%11 Python中的%C7。%B5f%3E%EBL%F3%1E5%13%21%EF%A3%A3'#

我已经研究了很多,由于我的新手编码技能,我无法设法在vb.net中执行以下操作。任何人都可以请赐教吗?

我需要做同样的事情: 从十六进制表示转换为散列的字节串值。

在此先感谢

回答

0

我很惊讶有没有把一个十六进制字符串成字节数组更简单的方法,但我并没有迅速找到一个所以这里是硬的方式:

Dim hex As String = "76a36f1d11c72eb5663eeb4cf31e351321efa3a3" 

    'prepend leading zero if needed 
    If hex.Length Mod 2 <> 0 Then 
    hex = " " & hex 
    End If 


    Dim bytes As Byte() = New Byte((hex.Length \ 2) - 1) {} 
    For byteNum As Int32 = 0 To bytes.Length - 1 

    bytes(byteNum) = Byte.Parse(hex.Substring(byteNum * 2, 2), 
      Globalization.NumberStyles.AllowHexSpecifier) 

    Next 

    'convert to an ansi string and escape 
    Dim final As String =Uri.EscapeDataString( 
     System.Text.Encoding.Default.GetString(bytes))