Created
May 16, 2017 10:07
-
-
Save 0x6d61/64a77e4734b413b08bafddbfb0f61757 to your computer and use it in GitHub Desktop.
C# Simple substitution cipher
This file contains 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; | |
class DecodeCaesarTool { | |
public static void Main(string[] args) { | |
if(args.Length == 0 ) { | |
Console.WriteLine("DecodeCaesar.exe <cipher text>"); | |
}else{ | |
for(int i = 1;i<26;i++) { | |
List<char> r = DecodeCaesar(args[0],i); | |
Console.WriteLine("seed:{0},{1}",i,new String(r.ToArray())); | |
} | |
} | |
} | |
private static List<char> DecodeCaesar(string chiher,int seed) { | |
char[] alpha = "abcdefghijklmnopqrstuvwxyz".ToCharArray(); | |
List<char> list = new List<char>(alpha); | |
List<char> result = new List<char>(); | |
char[] text = chiher.ToLower().ToCharArray(); | |
for(int i = 0;i<text.Length;i++) { | |
if(!Char.IsNumber(text[i])) { | |
if(25 >= (list.IndexOf(text[i]) + seed)) { | |
result.Add(list[list.IndexOf(text[i]) + seed]); | |
}else{ | |
result.Add(list[Math.Abs(seed - list.IndexOf(text[i]))]); | |
} | |
}else{ | |
continue; | |
} | |
} | |
return result; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment