Hello! This feature is implemented in C #. It already contains the text to be encrypted / decrypted. I do not know the language with # and therefore I ask for help. You can redo this function so that the following is displayed on startup:

  • Enter the name of the source file: // enter the type name d:\rfc795.txt , it is encrypted, and after
  • Enter the name of the encrypted file: // enter the name of the file into which the encrypted information will be written, for example. d:\q.txt , then the file is decrypted.
  • Enter the name of the decrypted file: // here we write the name of the file, in which the decrypted information of the d:\qq.txt type will be written

You can also write a function that will display the time in milliseconds spent on encrypting and decrypting a file.

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Crypto; namespace AESDemo { class Program { static void Main(string[] args) { // Примерно так. Как точно, должно быть описано там откуда скачан проект. // В имеющейся же реализации aes комментариев практически нет. Так что разобраться трудно. string message = "My Secret Message"; string key = "my_secret_key"; Console.WriteLine("Исходное сообщение: '{0}'", message); byte[] message_bytes = Encoding.Default.GetBytes(message); byte[] key_bytes = new byte[64]; Encoding.Default.GetBytes(key, 0, key.Length, key_bytes, 0); byte[] enc_message_bytes = null; uint msgnum = 1; AES.AES_CCM_Encrypt(message_bytes, key_bytes, out enc_message_bytes, 1, msgnum); Console.WriteLine("Зашифрованное сообщение: '{0}'", Encoding.Default.GetString(enc_message_bytes)); byte[] dec_message_bytes = null; AES.AES_CCM_Decrypt(enc_message_bytes, key_bytes, out dec_message_bytes, 1, out msgnum); Console.WriteLine("Расшифрованное сообщение: '{0}'", Encoding.Default.GetString(dec_message_bytes)); Console.ReadKey(); } } } 
  • Homework? - alexlz
  • something like that. - Maverick

1 answer 1

Sisharp children in school will soon be taught, and you do not understand. And the rules here are forbidden to post in the style of "make for me." For the future.

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.IO; using Crypto; namespace AESDemo { class Program { const string KEY = "my_secret_key"; static void Main(string[] args) { Stopwatch timer = new Stopwatch(); Console.Write("Enter source (original) file name: "); string srcPath = Console.ReadLine(); Console.Write("Enter destination (encrypted) file name: "); string dstPath = Console.ReadLine(); string message = File.ReadAllText(srcPath); byte[] message_bytes = Encoding.Default.GetBytes(message); byte[] key_bytes = new byte[64]; Encoding.Default.GetBytes(KEY, 0, KEY.Length, key_bytes, 0); byte[] enc_message_bytes = null; timer.Start(); AES.AES_CCM_Encrypt(message_bytes, key_bytes, out enc_message_bytes, 1, 1); timer.Stop(); string enc_message = Encoding.Default.GetString(enc_message_bytes); File.WriteAllText(dstPath, enc_message); Console.WriteLine("Encryption time: {0}ms", timer.ElapsedMilliseconds); Console.Write("Enter source (encrypted) file name: "); srcPath = Console.ReadLine(); Console.Write("Enter destination (decrypted) file name: "); dstPath = Console.ReadLine(); byte[] dec_message_bytes = null; timer.Restart(); AES.AES_CCM_Decrypt(enc_message_bytes, key_bytes, out dec_message_bytes, 1, out msgnum); timer.Stop(); string dec_message = Encoding.Default.GetString(dec_message_bytes); Console.WriteLine("Decryption time: {0}ms", timer.ElapsedMilliseconds); File.WriteAllText(dstPath, dec_message); Console.ReadKey(); } } } 
  • 3
    You would really have written only the key points, but the vehicle will not learn anything. - VladD