XOREncryption/C#/Main.cs

25 lines
607 B
C#
Raw Permalink Normal View History

2013-10-07 04:15:32 +04:00
using System;
class XOREncryption
{
private static string encryptDecrypt(string input) {
2013-10-07 04:16:14 +04:00
char[] key = {'K', 'C', 'Q'}; //Any chars will work, in an array of any size
2013-10-07 04:15:32 +04:00
char[] output = new char[input.Length];
for(int i = 0; i < input.Length; i++) {
output[i] = (char) (input[i] ^ key[i % key.Length]);
}
return new string(output);
}
public static void Main (string[] args)
{
string encrypted = encryptDecrypt("kylewbanks.com");
Console.WriteLine ("Encrypted:" + encrypted);
string decrypted = encryptDecrypt(encrypted);
Console.WriteLine ("Decrypted:" + decrypted);
}
}