Exemple #1
0
        public static byte[] CNFLEncoding(string Message, string key, byte s0)
        {
            Magenta magenta = new Magenta(Message, key);

            byte[] s = new byte[magenta.text.Length];
            s[0] = s0;
            for (int i = 1; i < magenta.text.Length; i++)
            {
                s[i] = (byte)(s[i - 1] + 1);
            }

            byte[] C  = new byte[magenta.text.Length];
            byte[] Ci = new byte[16];
            byte[] Pi = new byte[16];
            byte[] ki;
            byte[] tmp = new byte[16];

            for (int i = 0; i < magenta.text.Length; i += 16)
            {
                for (int j = 0; j < 16; j++)
                {
                    Pi[j]  = magenta.text[j + i];
                    tmp[j] = s[j + i];
                }
                ki = Encoding(ToString(tmp), key);
                Ci = Encoding(Pi, ki);

                for (int j = 0; j < 16; j++)
                {
                    C[i + j] = Ci[j];
                }
            }

            return(C);
        }
Exemple #2
0
 public static byte[] GetHash(byte[] text)
 {
     byte[] E = new byte[16];
     byte[] h = new byte[16];
     for (int i = 0; i < 16; i++)
     {
         h[i] = 0x00;
     }
     byte[] M = new byte[16];
     byte[] A = new byte[16];
     for (int i = 0; i < text.Length; i = i + 16)
     {
         for (int j = 0; j < 16; j++)
         {
             M[j] = text[i + j];
             A[j] = (byte)(M[j] ^ h[j]);
         }
         E = Magenta.Encoding(A, M);
         for (int j = 0; j < 16; j++)
         {
             h[j] = (byte)(E[j] ^ A[j]);
         }
     }
     return(h);
 }
Exemple #3
0
        public static byte[] Encoding(byte[] blockText, byte[] blockKey)
        {
            Magenta a = new Magenta();

            byte[,] res = new byte[2, 8];
            // function V
            byte[] tmp = new byte[8];
            byte[] kL  = new byte[8];
            byte[] kR  = new byte[8];
            byte[] bL  = new byte[8];
            byte[] bR  = new byte[8];
            for (int i = 0; i < 8; i++)
            {
                bL[i] = blockText[i];
                bR[i] = blockText[i + 8];
                kL[i] = blockKey[i];
                kR[i] = blockKey[i + 8];
            }
            for (int i = 0; i < 8; i++)
            {
                tmp[i] = bL[i];
                bL[i]  = bR[i];
                bR[i]  = tmp[i];
            }
            for (int j = 0; j < 6; j++)
            {
                if (j != 2 || j != 3)
                {
                    res = a.F(bL, bR, kL);
                }
                else
                {
                    res = a.F(bL, bR, kR);
                }
                for (int i = 0; i < 8; i++)
                {
                    bL[i] = res[0, i];
                    bR[i] = res[1, i];
                }
            }

            byte[] blockLR = new byte[16];
            for (int i = 0; i < 8; i++)
            {
                blockLR[i]     = bL[i];
                blockLR[i + 8] = bR[i];
            }
            return(blockLR);
        }
Exemple #4
0
        public static byte[] Encoding(string Text, string Key)
        {
            Magenta M = new Magenta(Text, Key);

            // разделение каждого 16-битного блока текста на левый и правый
            for (int j = 0; j < M.text.Length; j += 16)
            {
                for (int i = 0; i < 8; i++)
                {
                    M.blockL[i] = M.text[i + j];
                    M.blockR[i] = M.text[i + j + 8];
                }
                M.encoding();
            }

            return(M.EncodedData);
        }