I'm currently pulling my hair out trying to generate an info_hash from a torrent file I've downloaded. I created the Torrent file using uTorrent and using PeerTracker as my tracking software.
I'm using an updated version of the code found here:
https://code.google.com/p/rouge-server/source/browse/trunk/driver/objective-c/RougeDriver/BEncoding.m?r=88
{
announce = "http://sub.url.com:8080/announce.php";
"created by" = "uTorrent/1870";
"creation date" = 1425134140;
encoding = "UTF-8";
info = {
length = 4;
name = "test.txt";
"piece length" = 16384;
pieces = "\U00a9J\U00e8\U00c2\U00c3\U00b1\U00f5\U00b6L\bs\U201d\U00eb\U00c8\U00e1\U00f2/\U00aa\U201d";
};
}
Below is the exact encoding method I'm using:
+ (void)encode:(id)object toString:(NSMutableString *)string
{
if([object isKindOfClass:[NSDictionary class]])
{
NSDictionary *dictionary = (NSDictionary *)object;
[string appendString:@"d"];
for(id key in [dictionary allKeys])
{
[self encode:key toString:string];
[self encode:[dictionary objectForKey:key] toString:string];
}
[string appendString:@"e"];
}
else if([object isKindOfClass:[NSString class]])
{
NSString *stringObject = (NSString *)object;
NSString *format = @"%lu:%@";
[string appendFormat:format, [string length], stringObject];
}
else if([object isKindOfClass:[NSArray class]])
{
NSArray *array = (NSArray *)object;
[string appendString:@"l"];
for(id item in array)
{
[self encode:item toString:string];
}
[string appendString:@"e"];
}
else if([object isKindOfClass:[NSNumber class]])
{
NSNumber *number = (NSNumber *)object;
NSString *format = @"i%de";
[string appendFormat:format, [number intValue]];
}
}
This is my first time working with Torrents and bencoding. I know I'm only supposed to Encode the "info" dictionary contained within the main dictionary.
Does anyone one know where I could be going wrong here?