示例#1
0
        public AesMatrix GetSimpleXOR()
        {
            var simpleXor = new AesMatrix();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    simpleXor.matrix[i, j] = Convert.ToByte(
                        this.key.matrix[i, j] ^ this.simpleText.matrix[i, j]
                        );
                }
            }
            return(simpleXor);
        }
示例#2
0
        static void Main(string[] args)
        {
            try
            {
                var simpleTextBytes = File.ReadAllBytes("./arquivo/texto.txt");
                Console.WriteLine("Lendo texto simples da pasta ./arquivo/texto.txt");
                var keyBytes = File.ReadAllBytes("./chave/chave.txt");
                Console.WriteLine("Lendo chave da pasta ./chave/chave.txt");

                var key = new AesMatrix(keyBytes);
                var simpleTextMatrix = new ByteMatrix(simpleTextBytes);
                Console.WriteLine(simpleTextMatrix.byteMatrix.Count);
                byte[] bte  = new byte[simpleTextMatrix.byteMatrix.Count * 16];
                var    loop = 1;
                foreach (var simpleText in simpleTextMatrix.byteMatrix)
                {
                    Console.WriteLine("****Chave****");
                    key.Print();
                    Console.WriteLine("****Texto simples****");
                    simpleText.Print();
                    var keyScheduler = new RoundKey(key).getAesMatrixCifred();
                    var simpleXor    = new SimpleXor(key, simpleText).GetSimpleXOR();
                    var cifred       = new MatrixRoundKey(simpleXor).GetRounds(keyScheduler);
                    Console.WriteLine("****Texto cifrado****");
                    cifred.Print();
                    for (var i = 0; i < 4; i++)
                    {
                        for (int b = 0; b < 4; b++)
                        {
                            bte[b * loop] = cifred.matrix[b, i];
                        }
                    }
                    loop++;
                }
                File.WriteAllBytes("./cifragem/cifragem.txt", bte);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Texto cifrado salvo na pasta ./cigragem/cigragem.txt");
                Console.ForegroundColor = ConsoleColor.White;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
示例#3
0
        private AesMatrix PrintKeyScheduler(int roundKey)
        {
            Console.WriteLine(String.Format("*****Round Key {0} ******", roundKey));
            var       initialKey = ((roundKey + 1) * 4) - 4;
            AesMatrix matrix     = new AesMatrix();

            for (int i = 0; i < 4; i++)

            {
                for (int j = initialKey; j < (roundKey + 1) * 4; j++)
                {
                    Console.Write(this.keyScheduler[i, j].ToString("X2") + " ");
                    if ((roundKey + 1) * 4 == 44)
                    {
                        matrix.matrix[i, j - 40] = this.keyScheduler[i, j];
                    }
                }
                Console.WriteLine();
            }
            return(matrix);
        }
示例#4
0
 public MatrixRoundKey(AesMatrix crifredText)
 {
     this.crifredText = crifredText;
 }
示例#5
0
 public SimpleXor(AesMatrix key, AesMatrix simpleText)
 {
     this.key        = key;
     this.simpleText = simpleText;
 }
示例#6
0
 public RoundKey(AesMatrix aesMatrix)
 {
     this.aesMatrix    = aesMatrix;
     this.keyScheduler = new byte[4, 44];
 }