Strange characters... how are they created?

D

Daniel Waite

This isn't a Ruby-specific question, I suppose, but it's the language
I'm using for this project so I figured I'd ask here.

I've created a .torrent file, and between the bencoding is a
representation of the contents of the file I want to share (a small text
file):

20:Ÿø\îµÊ^Ω¬ ‡m$æÉ* ú0*

My question is, how does the BT client go from plain text to that? The
BT protocol spec says that pieces of data get SHA1'd, but I've never
seen a SHA1 hash look like that.

What am I missing?

In case the sample characters I pasted don't show up right, here's a
screen shot:

http://rabbitcreative.com/strange-charas.png
 
F

Frederick Cheung

This isn't a Ruby-specific question, I suppose, but it's the language
I'm using for this project so I figured I'd ask here.

I've created a .torrent file, and between the bencoding is a
representation of the contents of the file I want to share (a small =20=
text
file):

20:=C5=B8=C3=B8\=C3=AE=C2=B5=C3=8A^=CE=A9=C2=AC =E2=80=A1m$=C3=A6=C3=89*= =C3=BA0*

My question is, how does the BT client go from plain text to that? The
BT protocol spec says that pieces of data get SHA1'd, but I've never
seen a SHA1 hash look like that.

That sort of depends how you display your SHA1 hash. The result will =20
just be 20 random looking bytes (as you've got before), which doesn't =20=

display particularly nicely, which is why it's often written out in =20
hex. However if it's never going to be read by anything approaching a =20=

human you might as well just store the 20 bytes without trying to =20
encode them in anyway.

Fred
 
D

Daniel Waite

Frederick said:
That sort of depends how you display your SHA1 hash. The result will
just be 20 random looking bytes (as you've got before), which doesn't
display particularly nicely, which is why it's often written out in
hex. However if it's never going to be read by anything approaching a
human you might as well just store the 20 bytes without trying to
encode them in anyway.

Wow Frederick, you just opened my eyes! Thank you!

You said...
...which is why it's often written out in hex.

And on a whim I tried:

Digest::SHA1.digest(...)

And lo' and behold, I got much more bizarre looking output:
=> "?:\231\005?5&&U\203?@\217\261\216?%t"

I had no idea there was anything other than the hexdigest method, or
that the resulting hash could be represented so differently.

I feel like I'm moving forward, but I'm facing the wrong direction by a
degree or two.

The output, while more similar to what Transmission is generating, isn't
quite as "funky."
 
D

Daniel Waite

Daniel said:
The output, while more similar to what Transmission is generating, isn't
quite as "funky."

Scatch that "quite as funky" bit. I've hashed the SAME content and
gotten different results that what Transmission is generating. So I'm
still doing something wrong.
 
T

Todd Benson

T24gRmViIDYsIDIwMDggNDoxMSBBTSwgRGFuaWVsIFdhaXRlIDxyYWJiaXRibHVlQGdtYWlsLmNv
bT4gd3JvdGU6Cj4gRGFuaWVsIFdhaXRlIHdyb3RlOgo+ID4gVGhlIG91dHB1dCwgd2hpbGUgbW9y
ZSBzaW1pbGFyIHRvIHdoYXQgVHJhbnNtaXNzaW9uIGlzIGdlbmVyYXRpbmcsIGlzbid0Cj4gPiBx
dWl0ZSBhcyAiZnVua3kuIgo+Cj4gU2NhdGNoIHRoYXQgInF1aXRlIGFzIGZ1bmt5IiBiaXQuIEkn
dmUgaGFzaGVkIHRoZSBTQU1FIGNvbnRlbnQgYW5kCj4gZ290dGVuIGRpZmZlcmVudCByZXN1bHRz
IHRoYXQgd2hhdCBUcmFuc21pc3Npb24gaXMgZ2VuZXJhdGluZy4gU28gSSdtCj4gc3RpbGwgZG9p
bmcgc29tZXRoaW5nIHdyb25nLgo+Cj4gLS0KPiBQb3N0ZWQgdmlhIGh0dHA6Ly93d3cucnVieS1m
b3J1bS5jb20vLgo+Cj4KCkkgZG9uJ3Qga25vdyBhbnl0aGluZyBhYm91dCBiaXR0b3JyZW50LCBi
dXQKCnMgPSAnMjA6xbjDuFzDrsK1w4pezqnCrCDigKFtJMOmw4kqIMO6MConCnB1dHMgcy51bnBh
Y2soJ2gqJykKCm1pZ2h0IHBvaW50IHlvdSBpbiB0aGUgcmlnaHQgZGlyZWN0aW9uLgoKVG9kZAo=
 
D

Daniel Waite

Todd said:
I don't know anything about bittorrent, but

s = '20:Ÿø\îµÊ^Ω¬ ‡m$æÉ* ú0*'
puts s.unpack('h*')

might point you in the right direction.

That's an interesting operation, but nay, no directional change. (Also,
pasting it into IRB causes my machine to beep and pause. Dunno why
though. Perhaps the characters being pasted mean something special to
Ruby?)

I asked a friend of mine and he said that if you dump the output of the
digest method directly to a file, you'll get the funky output.

My guess is console does some kind of conversion -- possibly with
character encoding?

Anywho, the following...

require 'digest/sha1'

output = File.open('output', 'w+')
source = IO.read('./README_FOR_APP', 512)
output << Digest::SHA1.digest(source)
output.close

Yields the same "style" output that Transmission generates.
 
D

Daniel Waite

Todd said:
Oh, I see, you want to _create_ a digest. I misunderstood you.

It's possible too I wasn't very clear (it's happened before), in which
case I apologize. =)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top