diff --git a/GhettoCrypt.sln b/GhettoCrypt.sln index e33ff97..e6e60ff 100644 --- a/GhettoCrypt.sln +++ b/GhettoCrypt.sln @@ -12,6 +12,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GhettoCryptCLI", "GhettoCry {2B2CF665-F5E6-44DB-961F-FC81C88A356D} = {2B2CF665-F5E6-44DB-961F-FC81C88A356D} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SimpleTests", "SimpleTests\SimpleTests.vcxproj", "{9AE03058-3A1E-461E-A2C2-33C5C9D0F4CB}" + ProjectSection(ProjectDependencies) = postProject + {2B2CF665-F5E6-44DB-961F-FC81C88A356D} = {2B2CF665-F5E6-44DB-961F-FC81C88A356D} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -44,6 +49,14 @@ Global {719B8ECB-BA7B-471A-9B61-9EACA2289175}.Release|x64.Build.0 = Release|x64 {719B8ECB-BA7B-471A-9B61-9EACA2289175}.Release|x86.ActiveCfg = Release|Win32 {719B8ECB-BA7B-471A-9B61-9EACA2289175}.Release|x86.Build.0 = Release|Win32 + {9AE03058-3A1E-461E-A2C2-33C5C9D0F4CB}.Debug|x64.ActiveCfg = Debug|x64 + {9AE03058-3A1E-461E-A2C2-33C5C9D0F4CB}.Debug|x64.Build.0 = Debug|x64 + {9AE03058-3A1E-461E-A2C2-33C5C9D0F4CB}.Debug|x86.ActiveCfg = Debug|Win32 + {9AE03058-3A1E-461E-A2C2-33C5C9D0F4CB}.Debug|x86.Build.0 = Debug|Win32 + {9AE03058-3A1E-461E-A2C2-33C5C9D0F4CB}.Release|x64.ActiveCfg = Release|x64 + {9AE03058-3A1E-461E-A2C2-33C5C9D0F4CB}.Release|x64.Build.0 = Release|x64 + {9AE03058-3A1E-461E-A2C2-33C5C9D0F4CB}.Release|x86.ActiveCfg = Release|Win32 + {9AE03058-3A1E-461E-A2C2-33C5C9D0F4CB}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/GhettoCrypt/GhettoCrypt.vcxproj b/GhettoCrypt/GhettoCrypt.vcxproj index 6985c42..df4770d 100644 --- a/GhettoCrypt/GhettoCrypt.vcxproj +++ b/GhettoCrypt/GhettoCrypt.vcxproj @@ -143,6 +143,7 @@ + @@ -152,6 +153,7 @@ + diff --git a/GhettoCrypt/GhettoCrypt.vcxproj.filters b/GhettoCrypt/GhettoCrypt.vcxproj.filters index f47e6c3..4a79a55 100644 --- a/GhettoCrypt/GhettoCrypt.vcxproj.filters +++ b/GhettoCrypt/GhettoCrypt.vcxproj.filters @@ -24,6 +24,9 @@ Quelldateien + + Quelldateien + @@ -59,5 +62,8 @@ Headerdateien + + Headerdateien + \ No newline at end of file diff --git a/GhettoCrypt/Util.h b/GhettoCrypt/Util.h index 39cc47a..a4a8cf4 100644 --- a/GhettoCrypt/Util.h +++ b/GhettoCrypt/Util.h @@ -102,7 +102,12 @@ namespace GhettoCipher ss << (char)std::bitset<8>(bitstring.substr(i, 8)).to_ulong(); } - return ss.str(); + std::string text = ss.str(); + + // Dümp excess nullbytes + text.resize(strlen(text.data())); + + return text; } //! Will convert a flexible data block to a string @@ -117,7 +122,12 @@ namespace GhettoCipher ss << (char)std::bitset<8>(bitstring.substr(i, 8)).to_ulong(); } - return ss.str(); + std::string text = ss.str(); + + // Dümp excess nullbytes + text.resize(strlen(text.data())); + + return text; } //! Turns a fixed-size data block into a hex-string diff --git a/SimpleTests/EncryptEqualsDecrypt.cpp b/SimpleTests/EncryptEqualsDecrypt.cpp new file mode 100644 index 0000000..c5e2070 --- /dev/null +++ b/SimpleTests/EncryptEqualsDecrypt.cpp @@ -0,0 +1,44 @@ +#include "CppUnitTest.h" +#include "../GhettoCrypt/Cipher.h" +#include "../GhettoCrypt/Util.h" + +using namespace Microsoft::VisualStudio::CppUnitTestFramework; +using namespace GhettoCipher; + +namespace SimpleTests +{ + TEST_CLASS(EncryptEqualsDecrypt) + { + public: + + // Tests that a decrypted ciphertext equals its plaintrext version + TEST_METHOD(tEncryptEqualsDecrypt) + { + // Yes, this unit test should ideally exclude string conversions, + // But like this it's easier to see what it's doing + + // Define basic input + const std::string cleartext = "Hello, World!"; + const std::string password = "1234"; + + + // Instanciate our cipher and supply a key + const Cipher cipher(password); + + // Recode the ascii-string to bits + const Flexblock cleartext_bits = StringToBits(cleartext); + + // Encrypt our cleartext bits + const Flexblock ciphertext_bits = cipher.Encipher(cleartext_bits); + + // Decipher it again + const Flexblock decryptedBits = cipher.Decipher(ciphertext_bits); + + // Decode it back to ascii + const std::string decryptedText = BitsToString(decryptedBits); + + // Assert that the decrypted text equals the plaintext + Assert::AreEqual(cleartext.length(), decryptedText.length()); + } + }; +} diff --git a/SimpleTests/SimpleTests.vcxproj b/SimpleTests/SimpleTests.vcxproj new file mode 100644 index 0000000..5c1d799 --- /dev/null +++ b/SimpleTests/SimpleTests.vcxproj @@ -0,0 +1,169 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {9AE03058-3A1E-461E-A2C2-33C5C9D0F4CB} + Win32Proj + SimpleTests + 10.0 + NativeUnitTestProject + + + + DynamicLibrary + true + v142 + Unicode + false + + + DynamicLibrary + false + v142 + true + Unicode + false + + + DynamicLibrary + true + v142 + Unicode + false + + + DynamicLibrary + false + v142 + true + Unicode + false + + + + + + + + + + + + + + + + + + + + + false + + + true + + + true + + + false + + + + NotUsing + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + NotUsing + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + NotUsing + Level3 + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + _DEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + NotUsing + Level3 + true + true + true + $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + true + pch.h + + + Windows + true + true + $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) + + + + + + + + {2b2cf665-f5e6-44db-961f-fc81c88a356d} + + + + + + \ No newline at end of file diff --git a/SimpleTests/SimpleTests.vcxproj.filters b/SimpleTests/SimpleTests.vcxproj.filters new file mode 100644 index 0000000..88a0ce6 --- /dev/null +++ b/SimpleTests/SimpleTests.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Quelldateien + + + \ No newline at end of file