2012-11-20 33 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))