Advertisement
Guest User

Untitled

a guest
May 3rd, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1.     public static byte[] StringToByteArray(String hex)
  2.         {
  3.             int NumberChars = hex.Length;
  4.             byte[] bytes = new byte[NumberChars / 2];
  5.             for (int i = 0; i < NumberChars; i += 2)
  6.                 bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
  7.             return bytes;
  8.         }
  9.     private void button3_Click(object sender, EventArgs e)
  10.         {
  11.             string featherearring = "00804804A02A1CA20100000000000000D2F8B6FABBB700000000000000000000";
  12.             var strarray = StringToByteArray(featherearring);
  13.  
  14.             byte[] strarray_comp = Enc.Encrypt(strarray);
  15.  
  16.             string conv = BitConverter.ToString(strarray_comp);
  17.             MessageBox.Show(conv.Replace("-", ""));
  18.         }
  19.  
  20.  
  21.  
  22.         public static byte[] BitArrayToByteArray(BitArray bits)
  23.         {
  24.             byte[] bytes = new byte[bits.Length / 8];
  25.             bits.CopyTo(bytes, 0);
  26.             return bytes;
  27.         }
  28.         public static byte[] Encrypt(byte[] input)
  29.         {
  30.             BitArray source = new BitArray(input);
  31.             BitArray target = new BitArray(source.Length);
  32.  
  33.             target[26] = source[0];
  34.             target[31] = source[1];
  35.             target[17] = source[2];
  36.             target[10] = source[3];
  37.             target[30] = source[4];
  38.             target[16] = source[5];
  39.             target[24] = source[6];
  40.             target[2] = source[7];
  41.             target[29] = source[8];
  42.             target[8] = source[9];
  43.             target[20] = source[10];
  44.             target[15] = source[11];
  45.             target[28] = source[12];
  46.             target[11] = source[13];
  47.             target[13] = source[14];
  48.             target[4] = source[15];
  49.             target[19] = source[16];
  50.             target[23] = source[17];
  51.             target[0] = source[18];
  52.             target[12] = source[19];
  53.             target[14] = source[20];
  54.             target[27] = source[21];
  55.             target[6] = source[22];
  56.             target[18] = source[23];
  57.             target[21] = source[24];
  58.             target[3] = source[25];
  59.             target[9] = source[26];
  60.             target[7] = source[27];
  61.             target[22] = source[28];
  62.             target[1] = source[29];
  63.             target[25] = source[30];
  64.             target[5] = source[31];
  65.  
  66.             return BitArrayToByteArray(target);
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement