public static void Main(String[] args) { //user input Console.WriteLine("Enter some text: \n"); string user_input = Console.ReadLine(); Console.WriteLine("Input a key: \n"); int key = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(key); Console.WriteLine('\n'); //cipher string cipherEncrypt = AutoCipher.Ciphering(user_input, key); //output Console.WriteLine("Encrypted text: " + cipherEncrypt); Console.WriteLine('\n'); string decipher = AutoCipher.Decrypting(cipherEncrypt, key); Console.WriteLine("Decyphered text: " + decipher); Console.WriteLine('\n'); //brute force code Brute.force(cipherEncrypt); Brute.Analysis(cipherEncrypt); //key encryption string testing = Generate.AdvEncrypt(cipherEncrypt); Console.WriteLine("encrypted data 1: " + testing); Console.WriteLine('\n'); Console.WriteLine(Generate.AdvDecrypt(testing, key)); }
public static void force(string data) { List <string> output = new List <string>(); for (int i = 0; i < 26; i++) { string result = AutoCipher.Decrypting(data, i); output.Add(result); } output.ForEach(Console.WriteLine); }
public static string AdvDecrypt(string encryptedData, int shift) { var text = File.ReadAllText(path: @"path"); var key = new RSACryptoServiceProvider(); Console.WriteLine("encrypted data 2:" + encryptedData); Console.WriteLine('\n'); key.FromXmlString(text); Console.WriteLine("Xml string: " + text); Console.WriteLine('\n'); byte[] cipher = Convert.FromBase64String(encryptedData); byte[] decrypted = key.Decrypt(cipher, false); string final = Encoding.UTF8.GetString(decrypted); string output = AutoCipher.Decrypting(final, shift); return(output); }
public static void Analysis(string sign) { var characterCount = new Dictionary <char, int>(); foreach (var c in sign) { if (characterCount.ContainsKey(c)) { characterCount[c]++; } else if (!Char.IsLetter(c)) { continue; } else { characterCount[c] = 1; } } char key = characterCount.FirstOrDefault(x => x.Value == characterCount.Values.Max()).Key; Console.WriteLine("Max key: " + key); Console.WriteLine('\n'); Console.WriteLine("Key {0}, frequent: {1}, frequent two: {2}, frequency 3: {3}", (int)key, (int)'e', (int)'t', (int)'o'); Console.WriteLine('\n'); int new_key = (int)key - (int)'e'; int other_new_key = (int)key - (int)'t'; int other_other_key = (int)key - (int)'o'; Console.WriteLine(new_key + " " + other_new_key + " " + other_other_key); Console.WriteLine('\n'); Console.WriteLine("first test: " + AutoCipher.Decrypting(sign, new_key)); Console.WriteLine('\n'); Console.WriteLine("Second Test: " + AutoCipher.Decrypting(sign, other_new_key)); Console.WriteLine('\n'); Console.WriteLine("Third Test: " + AutoCipher.Decrypting(sign, other_other_key)); Console.WriteLine('\n'); }