Renamed cipher class
This commit is contained in:
parent
65f80b5d2d
commit
fbead384e2
@ -140,14 +140,14 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Feistel.cpp" />
|
||||
<ClCompile Include="FeistelMan.cpp" />
|
||||
<ClCompile Include="GhettoCipher.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Block.h" />
|
||||
<ClInclude Include="Config.h" />
|
||||
<ClInclude Include="Feistel.h" />
|
||||
<ClInclude Include="FeistelMan.h" />
|
||||
<ClInclude Include="GhettoCipher.h" />
|
||||
<ClInclude Include="Flexblock.h" />
|
||||
<ClInclude Include="Halfblock.h" />
|
||||
<ClInclude Include="Keyset.h" />
|
||||
|
@ -21,7 +21,7 @@
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="FeistelMan.cpp">
|
||||
<ClCompile Include="GhettoCipher.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
@ -44,10 +44,10 @@
|
||||
<ClInclude Include="Util.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FeistelMan.h">
|
||||
<ClInclude Include="Flexblock.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Flexblock.h">
|
||||
<ClInclude Include="GhettoCipher.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "FeistelMan.h"
|
||||
#include "GhettoCipher.h"
|
||||
#include "Util.h"
|
||||
#include <iostream>
|
||||
|
||||
FeistelMan::FeistelMan(const Block& key)
|
||||
GhettoCipher::GhettoCipher(const Block& key)
|
||||
:
|
||||
key { key }
|
||||
{
|
||||
@ -10,14 +10,14 @@ FeistelMan::FeistelMan(const Block& key)
|
||||
return;
|
||||
}
|
||||
|
||||
FeistelMan::FeistelMan(const std::string& password)
|
||||
GhettoCipher::GhettoCipher(const std::string& password)
|
||||
{
|
||||
key = PasswordToKey(password);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
FeistelMan::~FeistelMan()
|
||||
GhettoCipher::~GhettoCipher()
|
||||
{
|
||||
// Clear key memory
|
||||
ZeroKeyMemory();
|
||||
@ -25,7 +25,7 @@ FeistelMan::~FeistelMan()
|
||||
return;
|
||||
}
|
||||
|
||||
void FeistelMan::SetKey(const Block& key)
|
||||
void GhettoCipher::SetKey(const Block& key)
|
||||
{
|
||||
ZeroKeyMemory();
|
||||
|
||||
@ -33,7 +33,7 @@ void FeistelMan::SetKey(const Block& key)
|
||||
return;
|
||||
}
|
||||
|
||||
void FeistelMan::SetPassword(const std::string& password)
|
||||
void GhettoCipher::SetPassword(const std::string& password)
|
||||
{
|
||||
ZeroKeyMemory();
|
||||
|
||||
@ -41,7 +41,7 @@ void FeistelMan::SetPassword(const std::string& password)
|
||||
return;
|
||||
}
|
||||
|
||||
Flexblock FeistelMan::Encipher(const Flexblock& data, bool printReports) const
|
||||
Flexblock GhettoCipher::Encipher(const Flexblock& data, bool printProgress) const
|
||||
{
|
||||
// Split cleartext into blocks
|
||||
std::vector<Block> blocks;
|
||||
@ -57,7 +57,7 @@ Flexblock FeistelMan::Encipher(const Flexblock& data, bool printReports) const
|
||||
for (std::size_t i = 0; i < blocks.size(); i++)
|
||||
{
|
||||
// Print reports if desired. If we have > 1000 blocks, print one report every 100 blocks. Otherwise for every 10th block.
|
||||
if ((i % ((blocks.size() > 1000)? 100 : 10) == 0) && (printReports))
|
||||
if ((i % ((blocks.size() > 1000)? 100 : 10) == 0) && (printProgress))
|
||||
std::cout << "Encrypting... (Block " << i << " / " << blocks.size() << " - " << ((float)i*100 / blocks.size()) << "\%)" << std::endl;
|
||||
|
||||
const Block& lastBlock = (i>0) ? blocks[i-1] : emptyBlock;
|
||||
@ -73,7 +73,7 @@ Flexblock FeistelMan::Encipher(const Flexblock& data, bool printReports) const
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
Flexblock FeistelMan::Decipher(const Flexblock& data, bool printReports) const
|
||||
Flexblock GhettoCipher::Decipher(const Flexblock& data, bool printProgress) const
|
||||
{
|
||||
// Split ciphertext into blocks
|
||||
std::vector<Block> blocks;
|
||||
@ -92,7 +92,7 @@ Flexblock FeistelMan::Decipher(const Flexblock& data, bool printReports) const
|
||||
for (std::size_t i = 0; i < blocks.size(); i++)
|
||||
{
|
||||
// Print reports if desired. If we have > 1000 blocks, print one report every 100 blocks. Otherwise for every 10th block.
|
||||
if ((i % ((blocks.size() > 1000) ? 100 : 10) == 0) && (printReports))
|
||||
if ((i % ((blocks.size() > 1000) ? 100 : 10) == 0) && (printProgress))
|
||||
std::cout << "Decrypting... (Block " << i << " / " << blocks.size() << " - " << ((float)i*100/ blocks.size()) << "\%)" << std::endl;
|
||||
|
||||
Block tmpCopy = blocks[i];
|
||||
@ -112,11 +112,11 @@ Flexblock FeistelMan::Decipher(const Flexblock& data, bool printReports) const
|
||||
}
|
||||
|
||||
#pragma optimize("", off )
|
||||
void FeistelMan::ZeroKeyMemory()
|
||||
void GhettoCipher::ZeroKeyMemory()
|
||||
{
|
||||
key.reset();
|
||||
return;
|
||||
}
|
||||
#pragma optimize("", on )
|
||||
|
||||
const Block FeistelMan::emptyBlock;
|
||||
const Block GhettoCipher::emptyBlock;
|
@ -4,16 +4,16 @@
|
||||
|
||||
/** Class to apply a block cipher to messages of arbitrary length in a distributed manner
|
||||
*/
|
||||
class FeistelMan
|
||||
class GhettoCipher
|
||||
{
|
||||
public:
|
||||
explicit FeistelMan(const Block& key);
|
||||
explicit FeistelMan(const std::string& password);
|
||||
explicit GhettoCipher(const Block& key);
|
||||
explicit GhettoCipher(const std::string& password);
|
||||
|
||||
FeistelMan(const FeistelMan& other) = delete;
|
||||
FeistelMan(FeistelMan&& other) noexcept = delete;
|
||||
GhettoCipher(const GhettoCipher& other) = delete;
|
||||
GhettoCipher(GhettoCipher&& other) noexcept = delete;
|
||||
|
||||
~FeistelMan();
|
||||
~GhettoCipher();
|
||||
|
||||
//! Will set the key
|
||||
void SetKey(const Block& key);
|
||||
@ -22,10 +22,10 @@ public:
|
||||
void SetPassword(const std::string& password);
|
||||
|
||||
//! Will encipher a flexblock of data
|
||||
Flexblock Encipher(const Flexblock& data, bool printReports = false) const;
|
||||
Flexblock Encipher(const Flexblock& data, bool printProgress = false) const;
|
||||
|
||||
//! Will decipher a flexblock of data
|
||||
Flexblock Decipher(const Flexblock& data, bool printReports = false) const;
|
||||
Flexblock Decipher(const Flexblock& data, bool printProgress = false) const;
|
||||
|
||||
private:
|
||||
Block key;
|
BIN
decrypted.jpg
Normal file
BIN
decrypted.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
BIN
encrypted.jpg
Normal file
BIN
encrypted.jpg
Normal file
Binary file not shown.
BIN
images.jpg
Normal file
BIN
images.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
Loading…
x
Reference in New Issue
Block a user