Exemplo n.º 1
0
        public void Nuevo()
        {
            Productos produc = new Productos();

            produc.Id     = Convert.ToInt32(Request.Form["Id"]);
            produc.Nombre = Request.Form["Nombre"];
            produc.Precio = Convert.ToDouble(Request.Form["Precio"]);
            int      clave = Convert.ToInt32(Request.Form["clave"]);
            CifradoS cif   = new CifradoS();

            Encabezado encabezado = new Encabezado();
            var        folderName = Path.Combine("Resources", "Files");
            var        pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName);
            var        pathArch   = Path.Combine(pathToSave, "arbol.dat");

            if (Directory.Exists(pathToSave))
            {
                encabezado = encabezado.LeerEncabezado(pathArch);
            }
            Data.Instance.grado = encabezado.Grado;
            var pathP = Path.Combine(Directory.GetCurrentDirectory(), "Permutaciones.txt");

            if (clave >= 0 && clave <= 1023)
            {
                cif.DecimalaBinario(clave, 10);
                cif.LeerPermutaciones(pathP);
                cif.GenerarLLaves();
            }


            //LEER RAIZ
            Nodo <Productos> nodo = new Nodo <Productos>();
            int tamnodo           = nodo.FixedSizeText + (produc.FixedSizeText * nodo.Values.Length);
            //nodo.Values[0] = produc;
            //Productos n = new Productos();
            //n.Id = 23;
            //n.Nombre = "prueba";
            //n.Precio = 1.3;
            //nodo.Values[1] = n;
            //n.EscribirNodo(pathArch, encabezado.FixedSizeText, nodo);
            ////CUANDO SE AGREGA UN NODO
            //encabezado.Disponible = encabezado.Disponible + 1;
            //encabezado.EscribirEncabezado(pathArch);

            int posi = encabezado.FixedSizeText + tamnodo * encabezado.Raiz;
            Nodo <Productos> raiz = new Nodo <Productos>();

            raiz = produc.LeerNodo(pathArch, posi);
            string h = "hola";
            //nodo raiz = new Nodo<Productos>();
            //raiz.Values[0] = produc;
            //produc.Id = 2;
            //produc.Nombre = "probando";
            //produc.Precio = 2.3;
            //raiz.Values[1] = produc;
            //int pos = encabezado.FixedSizeText;
        }
Exemplo n.º 2
0
        public IActionResult SDES()
        {
            var file = Request.Form.Files[0];

            Encabezado encabezado = new Encabezado();
            int        clave      = Convert.ToInt32(Request.Form["clave"]);

            CifradoS cif        = new CifradoS();
            var      folderName = Path.Combine("Resources", "Files");
            var      pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName);
            var      pathP      = Path.Combine(Directory.GetCurrentDirectory(), "Permutaciones.txt");
            var      fullPath   = Path.Combine(pathToSave, "subido.txt");
            string   extension  = Path.GetExtension(file.FileName);

            using (var stream = new FileStream(fullPath, FileMode.Create))
            {
                file.CopyTo(stream);
            }
            if (clave >= 0 && clave <= 1023)
            {
                cif.DecimalaBinario(clave, 10);
                cif.LeerPermutaciones(pathP);
                cif.GenerarLLaves();

                if (extension == ".txt")
                {
                    var pathg = Path.Combine(pathToSave, "nuevo.scif");
                    using (var stream = new FileStream(pathg, FileMode.Create))
                    {
                    }

                    using (var stream = new FileStream(fullPath, FileMode.Open))
                    {
                        using (BinaryWriter wr = new BinaryWriter(stream))
                        {
                            using (BinaryReader br = new BinaryReader(stream))
                            {
                                var buffer = new byte[100];
                                while (br.BaseStream.Position != br.BaseStream.Length)
                                {
                                    buffer = br.ReadBytes(100); //llenar el buffer
                                    cif.ConvertirAscci(buffer); //Obtengo los codigos Ascci del buffer
                                    cif.InicioCifrado();        //inicio el cifrado del buffer
                                    cif.EscribirArch(pathg);
                                }
                            }
                        }
                        stream.Close();
                    }
                    var stream1 = new FileStream(pathg, FileMode.Open);

                    return(File(stream1, System.Net.Mime.MediaTypeNames.Application.Octet, "nuevo.scif"));
                }
                else if (extension == ".scif")
                {
                    var pathg = Path.Combine(pathToSave, "nuevo.txt");
                    using (var stream = new FileStream(pathg, FileMode.Create))
                    {
                    }

                    using (var stream = new FileStream(fullPath, FileMode.Open))
                    {
                        using (BinaryWriter wr = new BinaryWriter(stream))
                        {
                            using (BinaryReader br = new BinaryReader(stream))
                            {
                                var buffer = new byte[100];
                                while (br.BaseStream.Position != br.BaseStream.Length)
                                {
                                    buffer = br.ReadBytes(100); //llenar el buffer
                                    cif.ConvertirAscci(buffer); //Obtengo los codigos Ascci del buffer
                                    cif.InicioDesCifrado();     //inicio el cifrado del buffer
                                    cif.EscribirArchTXT(pathg);
                                }
                            }
                        }
                        stream.Close();
                    }
                    var stream1 = new FileStream(pathg, FileMode.Open);

                    return(File(stream1, System.Net.Mime.MediaTypeNames.Application.Octet, "nuevo.txt"));
                }
                else
                {
                    return(null);
                }
            }


            else
            {
                return(null);
            }
        }