static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("ShaleCo.Cryptography v1.0.0.0"); Console.WriteLine("Created by Shale Kuzmanovski 2014"); return; } switch (args[0]) { case "-scenario": if (args.Length < 3) { if (args.Length < 2) { Console.WriteLine("Please enter a message to encrypt."); return; } RunBasicScenario(args[1]); return; } if (args[2] == "-fileoutput") { if (args.Length < 4) { RunBasicScenario(args[1], true); return; } else { RunBasicScenario(args[1], true, args[3]); return; } } Console.WriteLine("Unrecognised command. Try -help to see available commands."); return; case "-race": if (args.Length < 2) { Console.WriteLine("Please provide a message. -race \"example\""); return; } CompareSpeeds(args[1]); break; case "-deskey": Console.WriteLine("DES Key. 64 Bit. 8 Bytes. 56 effiective bits."); WriteByteArray(Symmetric.GenerateDESKey()); return; case "-des3key": Console.WriteLine("DES3 Key. 192 Bit. 24 Bytes. 168 effiective bits."); WriteByteArray(Symmetric.Generate3DESKey()); return; case "-des3encrypt": if (args.Length != 3) { Console.WriteLine("Please provide a key in ASCII and a message."); Console.WriteLine("-des3encrypt \"abcdefghijklmnopqrstuvwx\" \"Hello World.\""); return; } var des3EncryptKey = args[1].GetBytes(); if (des3EncryptKey.Length != 24) { Console.WriteLine("Key was not the correct size: 192 bits."); return; } Console.WriteLine("Your encrypted message:"); WriteByteArray(Symmetric.Encrypt3DES(des3EncryptKey, args[2].GetBytes())); return; case "-desencrypt": if (args.Length != 3) { Console.WriteLine("Please provide a key in ASCII and a message."); Console.WriteLine("-desencrypt \"abcdefgh\" \"Hello World.\""); return; } var desEncryptKey = args[1].GetBytes(); if (desEncryptKey.Length != 8) { Console.WriteLine("Key was not the correct size: 64 bits."); return; } Console.WriteLine("Your encrypted message:"); WriteByteArray(Symmetric.EncryptDES(desEncryptKey, args[2].GetBytes())); return; case "-des3decrypt": if (args.Length != 3) { Console.WriteLine("Please provide a key in ASCII and a message."); Console.WriteLine("-des3decrypt \"abcdefghijklmnopqrstuvwx\" \"Hello World.\""); return; } var des3DecryptKey = args[1].GetBytes(); if (des3DecryptKey.Length != 24) { Console.WriteLine("Key was not the correct size: 192 bits."); return; } var des3DecryptCipherText = args[2].GetBytes(); if (des3DecryptCipherText.Length % 8 != 0) { Console.WriteLine("ERROR: ciphertext is not the correct size. must be a multiple of 64 bits."); return; } Console.WriteLine("Your decrypted message:"); WriteByteArray(Symmetric.Decrypt3DES(des3DecryptKey, des3DecryptCipherText)); return; case "-desdecrypt": if (args.Length != 3) { Console.WriteLine("Please provide a key in ASCII and a message."); Console.WriteLine("-desdecrypt \"abcdefgh\" \"Hello World.\""); return; } var desDecryptKey = args[1].GetBytes(); if (desDecryptKey.Length != 8) { Console.WriteLine("Key was not the correct size: 64 bits."); return; } var desDecryptCipherText = args[2].GetBytes(); if (desDecryptCipherText.Length % 8 != 0) { Console.WriteLine("ERROR: ciphertext is not the correct size. must be a multiple of 64 bits."); return; } Console.WriteLine("Your decrypted message:"); WriteByteArray(Symmetric.DecryptDES(desDecryptKey, desDecryptCipherText)); return; case "-rsakey": Console.WriteLine("RSA Key Pair"); Console.WriteLine(Asymmetric.GenerateRSAKeys()); return; case "-rsaencrypt": if (args.Length != 3) { Console.WriteLine("Please provide a key pair in decimal and a message in ASCCI."); Console.WriteLine("-rsaencrypt 373757,198399184603 \"Hello World.\""); return; } var keys = args[1].Split(','); if (keys.Length != 2) { Console.WriteLine("Invalid key, please provide a key pair in decimal"); Console.WriteLine("-rsaencrypt 373757,198399184603 \"Hello World.\""); return; } BigInteger key1; BigInteger key2; if (!BigInteger.TryParse(keys[0], out key1)) { Console.WriteLine("Invalid key, please provide a key pair in decimal"); Console.WriteLine("-rsaencrypt 373757,198399184603 \"Hello World.\""); return; } if (!BigInteger.TryParse(keys[1], out key2)) { Console.WriteLine("Invalid key, please provide a key pair in decimal"); Console.WriteLine("-rsaencrypt 373757,198399184603 \"Hello World.\""); return; } var message = args[2].GetBytes(); var cipherText = Asymmetric.EncryptRSA(new RSAKey(key1.ToByteArray(), key2.ToByteArray()), message); Console.WriteLine("Your encrypted message"); WriteByteArray(cipherText); return; case "-rsadecrypt": if (args.Length != 3) { Console.WriteLine("Please provide a key pair in decimal and a message in ASCCI."); Console.WriteLine("-rsadecrypt 373757,198399184603 \"Hello World.\""); return; } var decryptkeys = args[1].Split(','); if (decryptkeys.Length != 2) { Console.WriteLine("Invalid key, please provide a key pair in decimal"); Console.WriteLine("-rsadecrypt 373757,198399184603 \"Hello World.\""); return; } BigInteger decryptKey1; BigInteger decryptKey2; if (!BigInteger.TryParse(decryptkeys[0], out decryptKey1)) { Console.WriteLine("Invalid key, please provide a key pair in decimal"); Console.WriteLine("-rsadecrypt 373757,198399184603 \"Hello World.\""); return; } if (!BigInteger.TryParse(decryptkeys[1], out decryptKey2)) { Console.WriteLine("Invalid key, please provide a key pair in decimal"); Console.WriteLine("-rsadecrypt 373757,198399184603 \"Hello World.\""); return; } var decryptMessage = args[2].GetBytes(); var decryuptCipherText = Asymmetric.EncryptRSA(new RSAKey(decryptKey1.ToByteArray(), decryptKey2.ToByteArray()), decryptMessage); Console.WriteLine("Your decrypted message"); WriteByteArray(decryuptCipherText); return; case "-hash": if (args.Length != 2) { Console.WriteLine("Please enter a value in ASCII to hash"); return; } Console.WriteLine("Custom hash."); WriteByteArray(args[1].GetHash(HashTypes.SHALE)); return; #if DEBUG case "-scenariodebug": RunBasicScenarioDebug("Hello World. Foo Bar. !@#$%^&*"); return; #endif default: WriteHelp(); return; } }