public void EncryptFileTest() { OneTimePad cipher = new OneTimePad(); cipher.Encrypt(BASE_FILE, ENC_FILE); TestFileEnc(); }
public void DecryptNoKeyTest() { OneTimePad myCipher = new OneTimePad(); TestCtor(myCipher); myCipher.Decrypt(Convert.ToBase64String(Encoding.ASCII.GetBytes(TEST_STR))); }
public void EncryptNoKeyTest() { OneTimePad myCipher = new OneTimePad(); TestCtor(myCipher); myCipher.Encrypt(TEST_STR); }
static void TestStrEnc(OneTimePad cipher, string encStr, int keyLen) { byte[] generatedKey = cipher.GetKey(); Assert.IsNotNull(generatedKey, "Key was not Generated"); Assert.AreNotEqual(TEST_STR, encStr, "String did not encrypt"); Assert.AreEqual(keyLen, generatedKey.Length); }
public void EncryptStrTest() { OneTimePad myCipher = new OneTimePad(TEST_STR.Length); TestCtor(myCipher); myCipher.GenKey(); TestStrEnc(myCipher, myCipher.Encrypt(TEST_STR), TEST_STR.Length); }
public void Base() { var sut = new OneTimePad(); const string input = "secret"; var(pad, encoded) = sut.Encode(input); Assert.Equal(input, sut.Decode(pad, encoded)); }
public void GenKeyTest() { OneTimePad cipher = new OneTimePad(TEST_STR.Length); TestCtor(cipher); cipher.GenKey(); Assert.IsNotNull(cipher.GetKey(), "key was not intialized"); Assert.AreEqual(TEST_STR.Length, cipher.GetKey().Length, "Incorrect KeyLen Found"); }
public void LongString() { var sut = new OneTimePad(); const string input = "klYyn23RSBfVn8bqbQa2TRpTWjAkiHM5rL2YTDCl6DOQLdT2nj3kBb8GKLxdyj5Hx56SURDBGPFFEOKdwWA14YIJTwtHV7yqYqSbYOvYkbKKCXP3jsCMGH4xNyeGqQBoIKrR3hLh9YIqVLDp1Nq942xj10Qe8Nk67oCfMWYciqLnS6bwIiaRg5XIImegDHbqq6Iod79bZEAB7ziY2hoimMNBDDsEvgfP4e1V2kRewDSQgGWK09ErRB1YWNISW24jxCfIxjpeH1psyVYfGzhzn5bvaW9vkP9SKOqWcR9CLkFJpB6lmSl8phytGpFNw9AtZq8TqZ23pKm4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pjlvkGz18nHTqoxTfREaex7AcIJEofNGLuGb9jmODf6MbiscaeklZ1qMfg5gmLdPYiqz4KCQ55V5UJwWwljNCLPw3grVKRAsZtSohmaEK4VyaFaoNdGsfm2BsQ7oZvRQ62TvjVmbrmqBEV6paDktwuYyEfhFRW0beuwDapXvLnnzzYeZU4ZT5Yew2QiSItfq6y4ioYd48x1rcrBx1pYZ6za6D5LGkNgL9KQk6Bf3hY9TDBNM7YnjJGwUr1KGWh8SnCGcoLGqFMI2GvW7Yd2l86mGjBpF0j7aw7iJ2JEFaVZF3R0SmWUACtRgUCtMwFO13gkpz6Ct62MtbLpOTC4OboAdEYDuxNXMymHhYCAqsHgRgNy9Qc23Uzc0ntEZAiQg0Rbf3bCLR7u7IObl4k18HKHKnHEX3Aiyyv51opQXax18UUbw2Mbhz4NalIpgNkmvxlUuKdaUyEWCYKcbGCcRdKEG6eubcbnlSqRtwPI411qLzawuUSz5K9S2Y0l96IMdzkjjn5orisIlRlFVdIXM5ucw5LV6Z0MRT1BPxK2c6WVmpufakwXaISQrukBf71WY8cR49NRh8M"; var(pad, encoded) = sut.Encode(input); Assert.Equal(input, sut.Decode(pad, encoded)); }
public static void NotepadEncode() { string key = File.ReadAllText(RAVEN_TXT); Chiper encoder = new OneTimePad(key, alphabets); Chiper decoder = new OneTimePad(key, alphabets); string message = SAMPLE_TEXT; Encode(message, encoder, decoder); }
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)); }
public void SetKeyTest() { const int KEY_LEN = 10; OneTimePad encryptorOne = new OneTimePad(); OneTimePad encryptorTwo = new OneTimePad(KEY_LEN); TestCtor(encryptorOne); TestCtor(encryptorTwo); encryptorTwo.GenKey(); encryptorOne.SetKey(encryptorTwo.GetKey()); CompareKeys(encryptorTwo.GetKey(), encryptorOne.GetKey()); }
public override void Display() { base.Display(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("\nPress any any key to begin decryption..."); Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Decrypting..."); Console.ForegroundColor = ConsoleColor.White; try { if (FileHelper.CheckFileBase64(args[3])) { OneTimePad.DecryptFileBase64Pad(args[1], args[2], args[3]); } else { OneTimePad.DecryptFile(args[1], args[2], args[3]); } } catch { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nPress any key to return home..."); Console.ReadLine(); Program.NavigateHome(); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nDone!\n"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Press any key to return continue..."); Console.ReadLine(); Program.AddPage(new PadOptionsPage(Program, args)); Program.NavigateTo <PadOptionsPage>(); }
public void Fuzzy() { var sut = new OneTimePad(); const int inputLength = 10000; var stringBuilder = new StringBuilder(inputLength); var random = new Random(); const byte minSymbol = (byte)'0'; const byte maxSymbol = (byte)'~'; for (var i = 0; i < inputLength; i++) { stringBuilder.Append((char)random.Next(minSymbol, maxSymbol)); } var input = stringBuilder.ToString(); var(pad, encoded) = sut.Encode(input); Assert.Equal(input, sut.Decode(pad, encoded)); }
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 override void Display() { base.Display(); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nPress any any key to begin encryption..."); Console.ReadLine(); // TODO make global print with colors method Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Encrypting..."); Console.ForegroundColor = ConsoleColor.White; try { OneTimePad.EncryptFile(args[1], args[2], args[3]); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nPress any key to return home..."); Console.ReadLine(); Program.NavigateHome(); } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nDone!\n"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Press any key to return continue..."); Console.ReadLine(); Program.AddPage(new PadOptionsPage(Program, args)); Program.NavigateTo <PadOptionsPage>(); }
public Part2() { oneTimePad = new OneTimePad(); }
static void TestCtor(OneTimePad cipher) { Assert.IsNull(cipher.GetKey(), "Incorrect intialized key Found"); }
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))); }