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)); }