Last active
October 13, 2016 11:32
-
-
Save dretax/07cb36e27966b87256d0579ee85aba02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace iziprogzh4 | |
{ | |
internal class Program | |
{ | |
internal static string Caesar(string value, int shift, bool Encrypt = true) | |
{ | |
char[] buffer = value.ToCharArray(); | |
for (int i = 0; i < buffer.Length; i++) | |
{ | |
char letter = buffer[i]; | |
if (Encrypt) letter = (char)(letter + shift); | |
else letter = (char)(letter - shift); | |
if (letter > 'z') | |
{ | |
letter = (char)(letter - 26); | |
} | |
else if (letter < 'a') | |
{ | |
letter = (char)(letter + 26); | |
} | |
buffer[i] = letter; | |
} | |
return new string(buffer); | |
} | |
internal static void Main() | |
{ | |
string a = "test"; | |
string b = Caesar(a, 18); | |
string c = Caesar(b, -18); | |
string d = Caesar(a, 1); | |
string e = Caesar(d, -1); | |
string f = "exxegoexsrgi"; | |
string g = Caesar(f, -4); | |
Console.WriteLine(a); | |
Console.WriteLine(b); | |
Console.WriteLine(c); | |
Console.WriteLine(d); | |
Console.WriteLine(e); | |
Console.WriteLine(f); | |
Console.WriteLine(g); | |
Console.WriteLine(Caesar("buzi", 1)); | |
Console.WriteLine(Caesar("cvaj", 1, false)); | |
Console.ReadKey(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment