C#

  • Thread starter Virajitha Sarma
  • Start date
V

Virajitha Sarma

[StructLayout(LayoutKind.Explicit)]
public struct SampleUnion
{
[FieldOffset(0)] public uint dword;
[FieldOffset(0)] public byte[] bytes;
[FieldOffset(0)] public uint byte3;
[FieldOffset(8)] public uint byte2;
[FieldOffset(16)] public uint byte1;
[FieldOffset(24)] public uint byte0;
};

uint S(SampleUnion x, uint y)

i am calling a function "S". Depending on the value y, the function
should return the value of the expression "SBoxes[y][x.bytes##y])" (this
expression is written in c)... suppose y=1, then SBoxes[1][x.bytes1]...
where bytes1 is a member of the C# representation of C union. In the
same way for y=2,3,.... i should be able to compute the expression by
calling this function "S"...

In C, this can be done as..
uint S(SampleUnion x, uint y)
{
return(SBoxes[y][x.bytes##y]);
}

Here y is appended to bytes using "##". But i donot how i can do it in
C#....Due to this i am not able to proceed further.So any kind of help
is highly appreciated and will be waiting for any reply...

Thanku
 
R

Rana

You can write an indexer in SampleUnion that returns appropriate byteXX
usind select case ..

Then youe S becomes

uint S(SampleUnion x, uint y)
{
return(SBoxes[y][x[y]]);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top