Skip to content

Commit

Permalink
reto 24 c#
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Ramirez committed Jun 13, 2023
1 parent 2dc4642 commit 558a016
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Retos/Reto #24 - CIFRADO CÉSAR [Fácil]/borazuwarah.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
string texto = "MOUREDEV - PRIMO DE LAURA MOURE (LA RULETA DE LA SUERTE)";
int desplazamiento = 3;
string textoCifrado = CifrarCesar(texto, desplazamiento);

Console.WriteLine("Texto original: " + texto);
Console.WriteLine("Texto cifrado: " + textoCifrado);


Console.WriteLine("***************");
Console.WriteLine("Descrifrando");
Console.WriteLine("***************");
string Descifrado = DescifrarCesar(textoCifrado, desplazamiento);
Console.WriteLine("Texto Descifrado: " + Descifrado);
Console.ReadKey();

static string CifrarCesar(string texto, int desplazamiento)
{
string textoCifrado = "";

foreach (char c in texto)
{
if (char.IsLetter(c))
{
char cifrado = (char)(((c - 'A') + desplazamiento) % 26 + 'A');
textoCifrado += cifrado;
}
else
{
textoCifrado += c;
}
}

return textoCifrado;
}

static string DescifrarCesar(string textoCifrado, int desplazamiento)
{
string textoDescifrado = "";

foreach (char c in textoCifrado)
{
if (char.IsLetter(c))
{
char descifrado = (char)(((c - 'A') - desplazamiento + 26) % 26 + 'A');
textoDescifrado += descifrado;
}
else
{
textoDescifrado += c;
}
}

return textoDescifrado;
}

0 comments on commit 558a016

Please sign in to comment.