diff --git a/ChaosTests/Cipher/Arc4CryptTests.cpp b/ChaosTests/Cipher/Arc4CryptTests.cpp index b2192bc..67de73f 100644 --- a/ChaosTests/Cipher/Arc4CryptTests.cpp +++ b/ChaosTests/Cipher/Arc4CryptTests.cpp @@ -107,3 +107,66 @@ TEST(Arc4CryptTests, RekeyTest) ciphertext); } } + +TEST(Arc4CryptTests, EncryptOutIteratorUsageTest) +{ + const std::vector data = StrToU8Vec("The quick brown fox jumps over the lazy dog."); + + { + std::array key = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + + Arc4Crypt crypt(key.begin(), key.end()); + + std::array out; + out.fill(0); + + std::array expected = + { + 0xe6, 0x51, 0x06, 0x25, 0x81, 0x48, 0xa9, 0x44, 0xa7, 0xe3, 0x30, + 0x38, 0x65, 0x66, 0x76, 0x88, 0x0f, 0xed, 0xec, 0x6f, 0x72, 0x89, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + crypt.Encrypt(out.begin(), data.begin(), 22); + + ASSERT_EQ(expected, out); + } + + { + std::array key = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + + Arc4Crypt crypt(key.begin(), key.end()); + + std::array out; + out.fill(0); + + std::array expected = + { + 0xe6, 0x51, 0x06, 0x25, 0x81, 0x48, 0xa9, 0x44, 0xa7, 0xe3, 0x30, + 0x38, 0x65, 0x66, 0x76, 0x88, 0x0f, 0xed, 0xec, 0x6f, 0x72, 0x89, + 0xef, 0xa5, 0xfa, 0xe4, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + crypt.Encrypt(out.begin(), data.begin(), 27); + + ASSERT_EQ(expected, out); + } + + { + std::array key = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + + Arc4Crypt crypt(key.begin(), key.end()); + + std::array out; + out.fill(0); + + std::array expected; + expected.fill(0); + + crypt.Encrypt(out.begin(), data.begin(), 0); + + ASSERT_EQ(expected, out); + } +}