Are these two functions the same?

Posted by Ranhiru on Stack Overflow See other posts from Stack Overflow or by Ranhiru
Published on 2010-06-02T09:01:51Z Indexed on 2010/06/02 9:03 UTC
Read the original article Hit count: 239

Filed under:
|
|

There is a function in the AES algorithm, to multiply a byte by 2 in Galois Field.

This is the function given in a website

private static byte gfmultby02(byte b)
    {
      if (b < 0x80)
        return (byte)(int)(b <<1);
      else
        return (byte)( (int)(b << 1) ^ (int)(0x1b) );
    }

This is the function i wrote.

private static byte MulGF2(byte x)
            {
            if (x < 0x80)
                return (byte)(x << 1);
            else
            {
                return (byte)((x << 1) ^ 0x1b);

            }

}

What i need to know is, given any byte whether this will perform in the same manner. Actually I am worried about the extra conversion of to int and then again to byte. So far I have tested and it looks fine. Does the extra cast to int and then to byte make a difference?

© Stack Overflow or respective owner

Related posts about c#

Related posts about integer