Re: Java Integer.ParseInt translation to python

2005-02-09 Thread jicman
Nick Craig-Wood wrote:
> When I try your code I get this...
...
[clip]
...
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "", line 4, in PrepareHash
> TypeError: 'str' object is not callable
> >>>
>
> You cant do byte(int(byte,16)) - byte is a string!  So you haven't
> posted the actual code you ran...

you're right... What I ran was this:

def PrepareHash(HashStr):
  while len(HashStr) > 0:
byte = HashStr[0:2]
print byte,int(byte,16),chr(int(byte,16)) # & 0xff
HashStr = HashStr[2:]
  return byte

def Main():
  HashStr = "c17ce186ab94eeb0de8ae3b5b751a7c4d8e9edeb"
  HashStr = PrepareHash(HashStr)
  print "Prepared HashStr :",HashStr

Main()


> Java bytes are signed also just to add to the confusion.

Exactly... which is the problem.  I don't know what the heck the [byte]
in front of a variable does.  I may have to get into the java list.
YUK!

thanks.

josé

--
http://mail.python.org/mailman/listinfo/python-list


Re: Java Integer.ParseInt translation to python

2005-02-09 Thread jicman

John Machin wrote:
> jose isaias cabrera wrote:
> However some Java code (I can't believe that it was the Java code
that
> you posted) has printed NINE bytes which bear no relation that I can
> see to any of the TWENTY bytes that the posted Java code should have
> stowed in retBuf.

I know what you're saying, John.  That's what is encryptic about this
whole thing.  The [byte] call in front of any variable will turn the
variable value to a "byte".  If you look at the code at the java code
at the beginning,

>>>   byte[] retBuf = new byte[inString.length()/2];

this retBuf is an array of bytes.  Whatever that means in java.  And
yes, that is the right output or result.  Hmmm, maybe an array of bytes
will turn into retBuf[0]+retBuf[0] = the first letter... H

> You claim that "[EMAIL PROTECTED]" is the right answer -- what is the
question?

Well, how can I get that exact answer from python?

> What is it meant to be? Your routine is called PrepareHash; is it
> possible that you are seeing these 9 bytes _after_ hashing?

Well, now that you say that, it may be that there is a space there.
H, let me try that again...

> Funny
> hashing scheme; they usually give 4, 8, 16, etc bytes, but worth an
ask
> ...

yep, you're right...

-- 
http://mail.python.org/mailman/listinfo/python-list