CLASE EJECUTORA
using System;
namespace Enunciado_2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("INGRESE EL NOMBRE A ENCRIPTAR");
string cadena = Console.ReadLine();
cadena = cadena.ToUpper();
Encriptacion ObjEncrp = new Encriptacion(cadena);
Console.WriteLine("DESENCRIPTAR EL CODIGO");
Console.WriteLine("INGRESE EL CODIGO");
string cadena2 = Console.ReadLine();
ObjEncrp.Desencriptacion(cadena2);
Console.ReadKey();
}
}
}
CLASE CONVENCIONAL
using System;
namespace Enunciado_2
{
class Encriptacion
{
private string letra;
private char[] chars;
public Encriptacion()
{
this.letra = null;
this.chars = null;
}
public Encriptacion(string cadena)
{
chars = cadena.ToCharArray();
for (int i = 0; i < cadena.Length; i++)
{
letra = this.FormatEncript(cadena.Substring(i, 1));
chars[i] = Convert.ToChar(letra);
}
Console.WriteLine("NOMBRE ENCRIPTADO");
Console.WriteLine(chars);
}
public void Desencriptacion(string cadena2)
{
chars = cadena2.ToCharArray();
for (int i = 0; i < cadena2.Length; i++)
{
letra = this.FormatDesencript(cadena2.Substring(i, 1));
chars[i] = Convert.ToChar(letra);
}
Console.WriteLine("CODIGO DESENCRIPTADO");
Console.WriteLine(chars);
}
private string FormatEncript(string letra)
{
if (letra == "A") { return "0"; }
if (letra == "B") { return "1"; }
if (letra == "C") { return "2"; }
if (letra == "D") { return "3"; }
if (letra == "E") { return "4"; }
if (letra == "F") { return "5"; }
if (letra == "G") { return "6"; }
if (letra == "H") { return "7"; }
if (letra == "I") { return "8"; }
if (letra == "J") { return "9"; }
if (letra == "K") { return "!"; }
if (letra == "L") { return "#"; }
if (letra == "M") { return "$"; }
if (letra == "N") { return "%"; }
if (letra == "O") { return "/"; }
if (letra == "P") { return "("; }
if (letra == "Q") { return ")"; }
if (letra == "R") { return "="; }
if (letra == "S") { return "?"; }
if (letra == "T") { return "¿"; }
if (letra == "U") { return "+"; }
if (letra == "V") { return "*"; }
if (letra == "B") { return ">"; }
if (letra == "X") { return "-"; }
if (letra == "Y") { return "_"; }
if (letra == "Z") { return "<"; }
return "Letra no definida";
}
private string FormatDesencript(string letra)
{
if (letra == "0") { return "A"; }
if (letra == "1") { return "B"; }
if (letra == "2") { return "C"; }
if (letra == "n") { return "D"; }
if (letra == "4") { return "E"; }
if (letra == "5") { return "F"; }
if (letra == "6") { return "G"; }
if (letra == "7") { return "H"; }
if (letra == "8") { return "I"; }
if (letra == "9") { return "J"; }
if (letra == "!") { return "K"; }
if (letra == "#") { return "L"; }
if (letra == "$") { return "M"; }
if (letra == "%") { return "N"; }
if (letra == "/") { return "O"; }
if (letra == "(") { return "P"; }
if (letra == ")") { return "Q"; }
if (letra == "=") { return "R"; }
if (letra == "?") { return "S"; }
if (letra == "¿") { return "T"; }
if (letra == "+") { return "U"; }
if (letra == "*") { return "V"; }
if (letra == ">") { return "W"; }
if (letra == "-") { return "X"; }
if (letra == "_") { return "Y"; }
if (letra == "<") { return "Z"; }
return null;
}
}
}
No hay comentarios:
Publicar un comentario