Dear fellow devs,
I'm working on a task of converting some C++ code into C# . Unfortunately to be honest with you, I'm not very fluent with C++ so maybe I'm missing something simple.
Anyway, I have this unsigned char of 64 elements called
buffer with the following elements:
[0] = 'C'
[1] = 'P'
[2] = '0'
[3] = '4'
...
[12] = '€'
The rest of the elements are all \0 (not '0').
Then this unsigned char array is cast to unsigned long array (within a class) as follows:
typedef struct _SHA_MSG {
unsigned long W[80];
} sha1_key;
unsigned char buffer[64]={0};
buffer[0] = 'C';
buffer[1] = 'P';
buffer[2] = '0';
buffer[3] = 4 + '0';
buffer[12] = 0x80;
sha1_key* k = (sha1_key*)buffer;
However at this point, it changes drastically! For example
k.W contains :
[0] = 875581507
[3] = 128
[16] = 3435973836
[17] = 2641335238
[18] = 3865956
[19] = 18366288
[20] = 0
[21] = 0
[22] = 2130567168
[23] = 3435973836
etc, with most elements having value 0 or 3435973836.
What has just happened? Can someone kindly instruct any C# equivalent of this operation that yields these results (ideally without relying on IntPtr) ?
Thanks a lot!
Edit:
My C# code of this part is:
struct sha1_key
{
uint[] w;
public uint[] W
{
get { return w; }
set { w = value; }
}
}
sha1_key key = new sha1_key();
key.W[0] = 'C';
key.W[1] = 'P';
key.W[2] = '0';
key.W[3] = (char)(year + '0');
key.W[12] = (char)0x80;
As you can see, I have so far retained much of the code as it is in C++. I will improve upon it later, when I manage to get it working :)