J
Jesper Stocholm
I have an iterated function like this:
01 string Guid = System.Guid.NewGuid().ToString();
02 _bSeed = (new UnicodeEncoding()).GetBytes(Guid);
03
04 CreateHashChain(0,_bSeed,10000);
05
06 private void CreateHashChain(int i,byte[] b, int max)
07 {
08 SHA1 sha = new SHA1CryptoServiceProvider();
09 byte[] result;
10 result = sha.ComputeHash(b);
11 if (i < max)
12 {
13 i++;
14 CreateHashChain(i,result,max);
15 }
16 }
It takes a random byte-array as input and iterates a hashfunction over it
a fixed number of times.
Seen from a mathematical point of view, a hash-function (here SHA1) takes
an input bit string of arbitrary length and returns a bit string of
length 160.
In my case I need to make sure that the input to the hashfunction is
always 100bits, so I need to figure out how to do the following:
1.
How do I take the data from my seed (a string), truncate the first (least
significant) 100 _bits_ of it and then put it into a byte-array for later
input for SHA1?
2.
How do I take a byte-array (here the return value of the hash-function),
truncate the first (least significant) 100 _bits_ of it and then put it
BACK into a byte-array for later input for SHA1?
I hope you can help me with this,
)
Thanks,
01 string Guid = System.Guid.NewGuid().ToString();
02 _bSeed = (new UnicodeEncoding()).GetBytes(Guid);
03
04 CreateHashChain(0,_bSeed,10000);
05
06 private void CreateHashChain(int i,byte[] b, int max)
07 {
08 SHA1 sha = new SHA1CryptoServiceProvider();
09 byte[] result;
10 result = sha.ComputeHash(b);
11 if (i < max)
12 {
13 i++;
14 CreateHashChain(i,result,max);
15 }
16 }
It takes a random byte-array as input and iterates a hashfunction over it
a fixed number of times.
Seen from a mathematical point of view, a hash-function (here SHA1) takes
an input bit string of arbitrary length and returns a bit string of
length 160.
In my case I need to make sure that the input to the hashfunction is
always 100bits, so I need to figure out how to do the following:
1.
How do I take the data from my seed (a string), truncate the first (least
significant) 100 _bits_ of it and then put it into a byte-array for later
input for SHA1?
2.
How do I take a byte-array (here the return value of the hash-function),
truncate the first (least significant) 100 _bits_ of it and then put it
BACK into a byte-array for later input for SHA1?
I hope you can help me with this,
![Blush :o :o](/styles/default/custom/smilies/blush.gif)
Thanks,