I want to generate numbers (Set) like from 1 to 100 and get sha256 hash of each in separate Line.
Example :-
1 : 6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
2 : d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35
.
.
.
.
100: ad57366865126e55649ecb23ae1d48887544976efea46a48eb5d85a6eeb4d306
please help me in Code So i can learn more for completing and golang project.
It gets jumbled up … like 100 coming first(good Learning) ,…,i like to also ask you that this is for numbers – But how to get for alphabets like a,b,c …to z to generate sha256??
Hashes are built from []byte, but neither 1, nor 100, nor anything inbetween is []byte, so you need to specify first how you want to convert them to []byte.
So until we know, how you want to represent the numbers (as string? LE or BE? Bit-Width? Signed or unsigned?) none of the proposed solutions is actually correct…
i want -
for example
a ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb
b 3e23e8160039594a33894f6564e1b1348bbd7a0088d42c4acb73eeaed59c009d
.
.
.
z 594e519ae499312b29433b7dd8a97ff068defcba9755b6d5d00e84c524d67b06
Yeah, for strings or single chars it is (nearly) a no-brainer. You have them already in a certain encoding and treat single chars as strings of length one and then convert them into a []byte.
But I am asking how you want to encode numbers. That is an important question.
Lets say we have []byte{0xff}, I can read this either as -1 or as 255, depending on if I read it into int8 or uint8.
Or []byte{0x00, 0xff} can be interpreted as little endian 16 bit signed integer (-256), little endian 16 bit unsigned integer (65280), big endian signed or unsigned 16 bit integer (255).
So counting the usual bit widths (8, 16, 32, 64), endiannes and signedness plus simply rendering numbers as plain strings, we have about 1 + 4 * 2 * 2 = 17 ways to represent the number 1 as []byte, even more if you count in floats…
To answer your question about letters… sha256.Sum256([]byte("a")) should be hint enough to actually finish the job.
When you can’t combine @acim’s solution for numbers with my closing sentence after the horizontal ruler, you should take some steps back and start doing the go tour (again).