public ActionResult Decifrar(string Key, string ToUser) { var User = new Users(); var messages = User.GetMessages(); var StringList = new List <string>(); var ToRList = new List <string>(); foreach (MessagesElements elements in messages) { if ((elements.Transmitter == Request.Cookies["User"]["username"]) && (elements.Reciever == ToUser)) { StringList.Add(elements.text); ToRList.Add("1"); } else { if ((elements.Transmitter == ToUser) && (elements.Reciever == Request.Cookies["User"]["username"])) { StringList.Add(elements.text); ToRList.Add("0"); } } } //Decifrar cada mensaje con la llave que se recibiĆ³ SDES DecifradoSDES = new SDES(); var P10 = "8537926014"; var P8 = "79358216"; var P4 = "0321"; var EP = "01323210"; var IP = "63572014"; var ReverseIP = DecifradoSDES.GenerarIPInverso(IP); //generar claves var resultanteLS1 = DecifradoSDES.GenerarLS1(Key, P10); var K1 = DecifradoSDES.GenerarK1(resultanteLS1, P8); var K2 = DecifradoSDES.GenerarK2(resultanteLS1, P8); var BinaryList = DecifradoSDES.LecutraArchivoDecifrar(StringList); var MessagesList = new List <MessagesElements>(); var cifrar = false; var counter = 0; foreach (List <string> list in BinaryList) { var Message = new MessagesElements(); var response = string.Empty; foreach (string binary in list) { byte bytefinal = DecifradoSDES.CifrarODecifrar(binary, IP, EP, K1, P4, K2, ReverseIP, cifrar); response += (char)bytefinal; } Message.Transmitter = ToRList[counter] == "1" ? Request.Cookies["User"]["username"] : ToUser; Message.Reciever = ToRList[counter] == "1" ? ToUser : Request.Cookies["User"]["username"]; Message.text = response; MessagesList.Add(Message); counter++; } return(View(MessagesList)); }
public ActionResult Cifrar(string Key, string message, string ToUser) { SDES cifradoSDES = new SDES(); var P10 = "8537926014"; var P8 = "79358216"; var P4 = "0321"; var EP = "01323210"; var IP = "63572014"; var ReverseIP = cifradoSDES.GenerarIPInverso(IP); //generar claves var resultanteLS1 = cifradoSDES.GenerarLS1(Key, P10); var K1 = cifradoSDES.GenerarK1(resultanteLS1, P8); var K2 = cifradoSDES.GenerarK2(resultanteLS1, P8); //cifrar var BinaryList = cifradoSDES.LecturaArchivo(message); //var byteList = new List<byte>(); var ciphertext = string.Empty; var cifrar = true; foreach (string binary in BinaryList) { byte bytefinal = cifradoSDES.CifrarODecifrar(binary, IP, EP, K1, P4, K2, ReverseIP, cifrar); ciphertext += (char)bytefinal; } //enviar el texto MessagesElements elemento = new MessagesElements(); elemento.Transmitter = Request.Cookies["User"]["username"]; elemento.Reciever = ToUser; elemento.text = ciphertext; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:58992/"); var postjob = client.PostAsync("api/Messages", new StringContent(new JavaScriptSerializer().Serialize(elemento), Encoding.UTF8, "application/json")); postjob.Wait(); } mensajeValido = 1; return(RedirectToAction("Index")); }