Jump to content

How to detect a string in torrent file?

Recommended Posts


I'm working on a BEncoding class in VB.NET. It works great but actually byte strings are read as byte arrays because there can be stored binary data (files hashes for example).

How can I recognize a text string?

Link to comment
Share on other sites

  • 5 months later...

Dunno if you're still working on this, but here's some pointers for you:

Readable text has a whole range of characters - 0x0A and 0x0D for Line Feed and Carriage Return characters (newlines) and 0x20 (decimal 32) to 0x7E (decimal 126) for printable ASCII characters. So, if you want some code here it is:

Function IsReadableText(data As Byte()) As Boolean
For i As UInt64 = 0 To data.Length - 1
If Not ((data(i) >= 32 And data(i) <= 126) Or data(i) = 10 Or data(i) = 13) Then
Return False
End If
Return True
End Function

It's reasonably good performance too, as the instant a "non-readable" character is found it returns false.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...