Exemplo n.º 1
0
        public Task <IActionResult> DecipherZigZag([FromForm] CipherZigZagRequest DecipherZigZagRequest)
        {
            if (DecipherZigZagRequest.File.Length > 0)
            {
                if (!Directory.Exists(_environment.WebRootPath + "\\Decipher\\"))
                {
                    Directory.CreateDirectory(_environment.WebRootPath + "\\Decipher\\");
                }
                using var _fileStream = System.IO.File.Create(_environment.WebRootPath + "\\Decipher\\" + DecipherZigZagRequest.File.FileName);
                DecipherZigZagRequest.File.CopyTo(_fileStream);
                _fileStream.Flush();
                _fileStream.Close();

                ZCipher.Decipher(_environment.WebRootPath + "\\Decipher\\" + DecipherZigZagRequest.File.FileName, _environment.WebRootPath + "\\Decipher\\" + DecipherZigZagRequest.Name + ".txt", DecipherZigZagRequest.Key);
                return(GetFile(Convert.ToString(DecipherZigZagRequest.Name), "\\Decipher\\"));
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Desifrado ZigZag
        /// </summary>
        public void Decipher_ZigZag(int levels, IFormFile formFile, string path)
        {
            var fileByte = new byte[formFile.Length];
            var i        = 0;

            using (var lectura = new BinaryReader(File.Open(path, FileMode.Open)))
            {
                while (lectura.BaseStream.Position != lectura.BaseStream.Length)
                {
                    fileByte[i] = lectura.ReadByte();
                    i++;
                }
            }
            ZigZag zigZag       = new ZigZag();
            var    txtCifrado   = zigZag.Decipher(fileByte, levels);
            var    txtResultado = new byte[1];

            txtResultado = new byte[txtCifrado.Length];
            txtResultado = txtCifrado;
            var new_Path = Path.Combine($"Decipher", Path.GetFileNameWithoutExtension(path) + ".txt");

            save_File(new_Path, txtResultado);
        }
Exemplo n.º 3
0
        public async Task <FileStreamResult> decifrar(string method, [FromForm] ValuesDataTaken data)
        {
            switch (method)
            {
            case "zigzag":
                ZigZag.Decipher(new NumbersDataTaken {
                    File = data.File, levels = Convert.ToInt32(data.levels)
                });
                break;

            case "cesar":
                Cesar.Decipher(data);
                break;

            case "route":
                Route.Decipher(new NumbersDataTaken {
                    File = data.File, Name = data.Name, rows = Convert.ToInt32(data.rows), columns = Convert.ToInt32(data.columns)
                });
                break;

            default:
                break;
            }

            var memory = new MemoryStream();

            using (var stream = new FileStream($"{ data.Name}.txt", FileMode.Open))
            {
                await stream.CopyToAsync(memory);
            }

            memory.Position = 0;

            //Retorno del contenido del archivo en Postman.
            return(File(memory, MediaTypeNames.Application.Octet, $"{ data.Name}.txt"));
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            ValuesDataTaken data;
            string          method = "";

            Console.WriteLine("Escriba la ruta del archivo: ", data.File);
            Console.ReadLine();

            Console.WriteLine("Escriba nombre del nuevo archivo ", data.Name);
            Console.ReadLine();

            Console.WriteLine("Escriba la ruta del metodo a utilizar: ", method);
            Console.ReadLine();

            //Eleccion de cifrado.
            switch (method)
            {
            case "cipher/cesar":
                Console.WriteLine("Escriba la clave: ", data.word);
                Console.ReadLine();

                Cesar.Cipher(data);
                break;

            case "cipher/zigzag":
                Console.WriteLine("Escriba la cantidad de olas: ", data.levels);
                Console.ReadLine();

                ZigZag.Cipher(new NumbersDataTaken {
                    File = data.File, Name = data.Name, levels = Convert.ToInt32(data.levels)
                });
                break;

            case "cipher/route":
                Console.WriteLine("Escriba la cantidad de olas: ", data.rows);
                Console.ReadLine();

                Console.WriteLine("Escriba la cantidad de olas: ", data.columns);
                Console.ReadLine();

                Route.Cipher(new NumbersDataTaken {
                    File = data.File, Name = data.Name, rows = Convert.ToInt32(data.rows), columns = Convert.ToInt32(data.columns)
                });
                break;

            case "decipher/cesar":
                Console.WriteLine("Escriba la clave: ", data.word);
                Console.ReadLine();

                Cesar.Decipher(data);
                break;

            case "decipher/zigzag":
                Console.WriteLine("Escriba la cantidad de olas: ", data.levels);
                Console.ReadLine();

                ZigZag.Decipher(new NumbersDataTaken {
                    File = data.File, Name = data.Name, levels = Convert.ToInt32(data.levels)
                });
                break;

            case "decipher/route":
                Console.WriteLine("Escriba la cantidad de olas: ", data.rows);
                Console.ReadLine();

                Console.WriteLine("Escriba la cantidad de olas: ", data.columns);
                Console.ReadLine();

                Route.Decipher(new NumbersDataTaken {
                    File = data.File, Name = data.Name, rows = Convert.ToInt32(data.rows), columns = Convert.ToInt32(data.columns)
                });
                break;
            }
        }
 public async Task <FileStreamResult> decifrarZigZag([FromForm] NumbersDataTaken requestdata)
 {
     ZigZag.Decipher(requestdata);
     return(await Download($"temp\\{requestdata.Name}.txt"));
 }