public void DecryptNoKeyTest() { OneTimePad myCipher = new OneTimePad(); TestCtor(myCipher); myCipher.Decrypt(Convert.ToBase64String(Encoding.ASCII.GetBytes(TEST_STR))); }
public void DecryptFileTest() { OneTimePad cipher = new OneTimePad(); cipher.Encrypt(BASE_FILE, ENC_FILE); TestFileEnc(); cipher.Decrypt(ENC_FILE, DEC_FILE); TestFileDec(); }
public void DecryptStrTest() { OneTimePad myCipher = new OneTimePad(TEST_STR.Length); TestCtor(myCipher); myCipher.GenKey(); string encStr = myCipher.Encrypt(TEST_STR); TestStrEnc(myCipher, myCipher.Encrypt(TEST_STR), TEST_STR.Length); TestStrDec(encStr, myCipher.Decrypt(encStr)); }
static void Main(string[] args) { IEncrypt encrypter = new OneTimePad(); var encryptedBytes = File.ReadAllBytes("Passwords.cpt"); var password = new IncrementalString(_characters.ToCharArray(), 8); var binaryFormatter = new BinaryFormatter(); var memoryStream = new MemoryStream(); while (true) { var decryptedBytes = encrypter.Decrypt(encryptedBytes, password.Next()); memoryStream.Write(decryptedBytes, 0, decryptedBytes.Length); memoryStream.Position = 0; try { var deserialised = (SortedObservableCollection <Entry>)binaryFormatter.Deserialize(memoryStream); Console.WriteLine(@"Right: " + password); } catch (Exception ex) when(ex is DecoderFallbackException || ex is SerializationException || ex is NullReferenceException) { Console.WriteLine(@"Wrong: " + password); } } }
public void CheckConsistency() { byte[] bytes = new byte[] { 5, 8, 5, 1, 2, 3, 32, 64 }; byte[] key = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Assert.Equal(bytes, OneTimePad.Decrypt(key, OneTimePad.Encrypt(key, bytes))); }