0
$\begingroup$

Assuming that we use k = sha3.keccak_256()(pysha3 package).

How should one convert integer input for a function k.update(myinteger) so that the output will be correct?

example:

import sha3    

myinteger = 1064880000

k = sha3.keccak_256()
k.update(myinteger)
k.hexdigest()
$\endgroup$

closed as off-topic by e-sushi Nov 18 '17 at 18:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions are off-topic even if you are writing or debugging cryptographic code. Unless your question is specifically about how the cryptographic algorithm, protocol or side-channel (mitigation) works, you should look into asking on Stack Overflow instead." – e-sushi
If this question can be reworded to fit the rules in the help center, please edit the question.

1
$\begingroup$

Define 'correct'

That is less silly of an answer than you might think; SHA-3-256 is a function from bitstrings (or bytestrings) to 256 bit hashes; it has no predefined ideas about a mapping of an integer to those bitstrings; it'll work for any of them.

Now, the application which is using SHA-3 might have such a predefined idea, and hence might define a 'correct' way. However, there is nothing in the code segment above would define it, and we have no idea what application you are attempting to be compatible with.

If you have no predefined application, and are just looking for a plausible way, might I suggest converting the integer into a little-endian 4 byte string (or 8 byte, if the integer value might be above 4 billion). That's as good as any...

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.