Jump to content



Photo

Torrent Info Hash Encoding


  • This topic is locked This topic is locked
20 replies to this topic

#1 Decipher

Decipher

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 337 posts

Posted 10 June 2012 - 11:40 AM

I would like to programmatically check to see if a given tracker has information on the torrent I specify. This requires that the SHA-1 Info Hash of a torrent be encoded to make valid requests. I read from: http://nakkaya.com/2009/12/03/bittorrent-tracker-protocol/ If you don't pay attention to the spec and send this directly to tracker you will get an error this should be in URL Encoded form. Padding every two chars with % sign also doesn't work, been there done that don't waste your time. Any hex in the hash that corresponds to a unreserved character should be replaced,
a-z A-Z 0-9 -_.~

Partition the hex in to chunks of two and check if the hex corresponds to any of these values, if they do replace them with the unreserved char.

So that a hash such as,
123456789abcdef123456789abcdef123456789a

becomes,
%124Vx%9a%bc%de%f1%23Eg%89%ab%cd%ef%124Vx%9a

notice that hex 34 became 4 which is what it is in ASCII. You can test the correctness of your hashes using the tracker url but don't request from announce request from file,
http://some.tracker.com/file?info_hash=hash

If you get a torrent back that means you have the correct hash.

I have tried the above and failed. Here's my code:
$testStr = "123456789abcdef123456789abcdef123456789a" ConsoleWrite(_EncodeHash($testStr) & @CRLF) Func _EncodeHash($sString)     If (Not IsString($sString)) Or $sString = "" Then Return SetError(1, 0, 0)     Local $aArray = StringRegExp($sString, "(?s).{1," & 2 & "}", 3), $sEncodedHash For $i = 0 To UBound($aArray) -1     If StringInStr($sString, Chr(Dec($aArray[$i]))) Then      $sEncodedHash &= Chr(Dec($aArray[$i]))     Else      $sEncodedHash &= "%" & $aArray[$i]     EndIf     Next Return $sEncodedHash EndFunc

If you follow the first link in my post there is an example but I'm unfamiliar with the language being used. Thanks for any help.

Edited by Decipher, 10 June 2012 - 11:42 AM.

Posted Image





#2 Decipher

Decipher

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 337 posts

Posted 10 June 2012 - 02:13 PM

I'm actually stuck on this. ;) I'd appreciate any help or general suggestions that appropriately pertain to this topic.

Edited by Decipher, 10 June 2012 - 03:03 PM.

Posted Image

#3 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,834 posts

Posted 10 June 2012 - 02:21 PM

General suggestion #1

Don't bump your threads after only a few hours, unless you think you are important enough.
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#4 Decipher

Decipher

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 337 posts

Posted 10 June 2012 - 02:50 PM

Hey JohnOne, you're absolutely correct. I consider myself to be an important individual. I would usually have something negative to say but I'm being humble. I'll wait until after I've made six thousand posts and never decide to suggest not bumping threads unless the OP feels important. Thanks for your first suggestion. I can't wait to endure number two but I'd rather stay on topic. ;)
Posted Image

#5 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,834 posts

Posted 10 June 2012 - 03:06 PM

Ask and you shall receive.
  • Decipher likes this
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#6 guinness

guinness

    guinness

  • MVPs
  • 10,299 posts

Posted 10 June 2012 - 03:06 PM

Decipher,

This is forum etiquette. Plus the support you get is from people who want to help not have to help, so learn how to be patient.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_DesktopDimensions()_DisplayPassword()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUISetIcon()_Icon_Clear()/_Icon_Set()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringIsValid()_StringReplaceWholeWord()_StringStripChar()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()AutoIt SearchAutoIt3 PortableAutoItWinGetTitle()/AutoItWinSetTitle()CodingFileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIGetBkColor()LockFile()PasteBinSciTE JumpSignature CreatorWM_COPYDATAMore Examples...Updated: 11/04/2013


#7 Decipher

Decipher

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 337 posts

Posted 10 June 2012 - 03:11 PM

I understand that you bumped the thread repeating what was already said by JohnOne and that neither of you would like to help but instead litter. ;)
Posted Image

#8 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,834 posts

Posted 10 June 2012 - 03:14 PM

Believe it or not, we did help, you will wind up in the forum naughty box for bumping like that.
Now you know.

You're welcome.
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#9 Decipher

Decipher

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 337 posts

Posted 10 June 2012 - 03:19 PM

Thanks I solved the problem at hand.
$Topic = 1
$Reponse = 0
$Help = 0
Dim $Bump
If $Topic = 1 And $Reponse = 0 Then
$Bump = 1
EndIf
If $Bump >= 1 Then $Unnecessary_Posts = Random(2, 10)
Exit
Posted Image

#10 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,834 posts

Posted 10 June 2012 - 03:25 PM

$iPost += 1
  • Decipher likes this
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#11 Decipher

Decipher

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 337 posts

Posted 10 June 2012 - 03:53 PM

I just took this from the spec:
Note that all binary data in the URL (particularly info_hash and peer_id) must be properly escaped. This means any byte not in the set 0-9, a-z, A-Z, '.', '-', '_' and '~', must be encoded using the "%nn" format, where nn is the hexadecimal value of the byte. (See RFC1738 for details.)
For a 20-byte hash of x12x34x56x78x9axbcxdexf1x23x45x67x89xabxcdxefx12x34x56x78x9a,
The right encoded form is %124Vx%9A%BC%DE%F1%23Eg%89%AB%CD%EF%124Vx%9A
I think I realize what I'm doing wrong....... I'm still waiting for help guies and no, I'm not trying to bump this thread it is relevant information.
Posted Image

#12 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,325 posts

Posted 10 June 2012 - 04:03 PM

Decipher,

I do not like the tone you have taken so far in this thread - please alter it in future. ;)

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#13 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,834 posts

Posted 10 June 2012 - 04:08 PM

What I think you are doing wrong is trying to escape characters that do not need escaping.
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#14 Decipher

Decipher

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 337 posts

Posted 10 June 2012 - 04:09 PM

Yes ma'am, I have solved my problem by myself. Heres the code:
#include <array.au3> $INFOHASH = "123456789abcdef123456789abcdef123456789a" ConsoleWrite(_EncodeHash($INFOHASH) & @CRLF) Func _EncodeHash($sString)     If (Not IsString($sString)) Or $sString = "" Then Return SetError(1, 0, 0)     Local $aArray = StringRegExp($sString, "(?s).{1," & 2 & "}", 3), $sEncodedHash For $i = 0 To UBound($aArray) -1     If StringInStr("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_~", Chr(Dec($aArray[$i]))) Then      $sEncodedHash &= Chr(Dec($aArray[$i]))     Else      $sEncodedHash &= "%" & $aArray[$i]     EndIf     Next Return $sEncodedHash EndFunc ;%124Vx%9a%bc%de%f1%23Eg%89%ab%cd%ef%124Vx%9a ;%124Vx%9a%bc%de%f1%23Eg%89%ab%cd%ef%124Vx%9a

Would you mind telling exactly how long I shall wait in the future before bumping, if it is even allowed.

Edited by Decipher, 10 June 2012 - 04:10 PM.

Posted Image

#15 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,834 posts

Posted 10 June 2012 - 04:12 PM

24 hours more or less
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#16 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,325 posts

Posted 10 June 2012 - 04:13 PM

Decipher,

I am a "Sir", thank you! ;)

Like most public forums we prefer you not to bump your own thread within 24 hours. Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually. Or if not - tough! :)

M23
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#17 Decipher

Decipher

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 337 posts

Posted 10 June 2012 - 04:15 PM

I will from now on. ;)
Posted Image

#18 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 644 posts

Posted 10 June 2012 - 04:17 PM

I think you should wait atleast a day before bumping.
Some people have a thing called "A life", you've probably heard of it, and therefore can't be online all the time.
Post, wait, and if nothing, bump after 24 hours.
Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler

#19 Decipher

Decipher

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 337 posts

Posted 10 June 2012 - 04:23 PM

I think you should wait atleast a day before bumping.
Some people have a thing called "A life", you've probably heard of it, and therefore can't be online all the time.
Post, wait, and if nothing, bump after 24 hours.


@Maffe811,

Seriously, You have to bored out of your mind taking the time out of your precious life to say what has been said once than again by a mod.

Sorry Melba32 I had to tell this poor guy.

Edited by Decipher, 10 June 2012 - 04:23 PM.

Posted Image

#20 Maffe811

Maffe811

    Sir Longbottle

  • Active Members
  • PipPipPipPipPipPip
  • 644 posts

Posted 11 June 2012 - 01:03 AM

Well, not really, i was reading the topic and was quite entertained by your behaviour and i took my time even finding some snacks.
So when i finally got arround to post a reply, some had beaten me to it.

But from the post you made answearing JohnOne i was just waiting for you to step over the line and get thrown out.
You should read the forum rules, they mention:

Do not be obnoxious, rude or in general a nuisance to the smooth operation of the forum.


Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.Scripts:
Spoiler




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users