orange_in_space

mode_s parity112 in cs

Jan 31st, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1.         private uint modeS_Parity112bit(byte[] src)
  2.         {
  3.             if (src.Length != 11)
  4.             {
  5.                 throw new Exception("length of data is not correct");
  6.             }
  7.  
  8.             UInt32 poly = 0xfffa0480;
  9.             UInt32 data = (UInt32)((src[0] << 24) | (src[1] << 16) | (src[2] << 8) | (src[3]));
  10.             UInt32 data1 = (UInt32)((src[4] << 24) | (src[5] << 16) | (src[6] << 8) | (src[7]));
  11.             UInt32 data2 = (UInt32)((src[8] << 24) | (src[9] << 16) | (src[10] << 8));
  12.  
  13.  
  14.  
  15.             int i = 0;
  16.  
  17.             while (i < 88)
  18.             {
  19.  
  20.                 if ((data & 0x80000000) != 0)
  21.                 {
  22.                     data = data ^ poly;
  23.                 }
  24.                 data = data << 1;
  25.                 if ((data1 & 0x80000000) != 0)
  26.                 {
  27.                     data = data | 1;
  28.                 }
  29.                 data1 = data1 << 1;
  30.                 if ((data2 & 0x80000000) != 0)
  31.                 {
  32.                     data1 = data1 | 1;
  33.                 }
  34.  
  35.                 data2 = data2 << 1;
  36.                 i++;
  37.             }
  38.  
  39.             return Convert.ToUInt32((data & 0xffffff00) >> 8);
  40.         }
Advertisement
Add Comment
Please, Sign In to add comment