Renamed cipher class
This commit is contained in:
parent
65f80b5d2d
commit
fbead384e2
@ -140,14 +140,14 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Feistel.cpp" />
|
<ClCompile Include="Feistel.cpp" />
|
||||||
<ClCompile Include="FeistelMan.cpp" />
|
<ClCompile Include="GhettoCipher.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Block.h" />
|
<ClInclude Include="Block.h" />
|
||||||
<ClInclude Include="Config.h" />
|
<ClInclude Include="Config.h" />
|
||||||
<ClInclude Include="Feistel.h" />
|
<ClInclude Include="Feistel.h" />
|
||||||
<ClInclude Include="FeistelMan.h" />
|
<ClInclude Include="GhettoCipher.h" />
|
||||||
<ClInclude Include="Flexblock.h" />
|
<ClInclude Include="Flexblock.h" />
|
||||||
<ClInclude Include="Halfblock.h" />
|
<ClInclude Include="Halfblock.h" />
|
||||||
<ClInclude Include="Keyset.h" />
|
<ClInclude Include="Keyset.h" />
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<ClCompile Include="main.cpp">
|
<ClCompile Include="main.cpp">
|
||||||
<Filter>Quelldateien</Filter>
|
<Filter>Quelldateien</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="FeistelMan.cpp">
|
<ClCompile Include="GhettoCipher.cpp">
|
||||||
<Filter>Quelldateien</Filter>
|
<Filter>Quelldateien</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -44,10 +44,10 @@
|
|||||||
<ClInclude Include="Util.h">
|
<ClInclude Include="Util.h">
|
||||||
<Filter>Headerdateien</Filter>
|
<Filter>Headerdateien</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="FeistelMan.h">
|
<ClInclude Include="Flexblock.h">
|
||||||
<Filter>Headerdateien</Filter>
|
<Filter>Headerdateien</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Flexblock.h">
|
<ClInclude Include="GhettoCipher.h">
|
||||||
<Filter>Headerdateien</Filter>
|
<Filter>Headerdateien</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#include "FeistelMan.h"
|
#include "GhettoCipher.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
FeistelMan::FeistelMan(const Block& key)
|
GhettoCipher::GhettoCipher(const Block& key)
|
||||||
:
|
:
|
||||||
key { key }
|
key { key }
|
||||||
{
|
{
|
||||||
@ -10,14 +10,14 @@ FeistelMan::FeistelMan(const Block& key)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FeistelMan::FeistelMan(const std::string& password)
|
GhettoCipher::GhettoCipher(const std::string& password)
|
||||||
{
|
{
|
||||||
key = PasswordToKey(password);
|
key = PasswordToKey(password);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FeistelMan::~FeistelMan()
|
GhettoCipher::~GhettoCipher()
|
||||||
{
|
{
|
||||||
// Clear key memory
|
// Clear key memory
|
||||||
ZeroKeyMemory();
|
ZeroKeyMemory();
|
||||||
@ -25,7 +25,7 @@ FeistelMan::~FeistelMan()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeistelMan::SetKey(const Block& key)
|
void GhettoCipher::SetKey(const Block& key)
|
||||||
{
|
{
|
||||||
ZeroKeyMemory();
|
ZeroKeyMemory();
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ void FeistelMan::SetKey(const Block& key)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeistelMan::SetPassword(const std::string& password)
|
void GhettoCipher::SetPassword(const std::string& password)
|
||||||
{
|
{
|
||||||
ZeroKeyMemory();
|
ZeroKeyMemory();
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ void FeistelMan::SetPassword(const std::string& password)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Flexblock FeistelMan::Encipher(const Flexblock& data, bool printReports) const
|
Flexblock GhettoCipher::Encipher(const Flexblock& data, bool printProgress) const
|
||||||
{
|
{
|
||||||
// Split cleartext into blocks
|
// Split cleartext into blocks
|
||||||
std::vector<Block> 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++)
|
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.
|
// 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;
|
std::cout << "Encrypting... (Block " << i << " / " << blocks.size() << " - " << ((float)i*100 / blocks.size()) << "\%)" << std::endl;
|
||||||
|
|
||||||
const Block& lastBlock = (i>0) ? blocks[i-1] : emptyBlock;
|
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();
|
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
|
// Split ciphertext into blocks
|
||||||
std::vector<Block> 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++)
|
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.
|
// 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;
|
std::cout << "Decrypting... (Block " << i << " / " << blocks.size() << " - " << ((float)i*100/ blocks.size()) << "\%)" << std::endl;
|
||||||
|
|
||||||
Block tmpCopy = blocks[i];
|
Block tmpCopy = blocks[i];
|
||||||
@ -112,11 +112,11 @@ Flexblock FeistelMan::Decipher(const Flexblock& data, bool printReports) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma optimize("", off )
|
#pragma optimize("", off )
|
||||||
void FeistelMan::ZeroKeyMemory()
|
void GhettoCipher::ZeroKeyMemory()
|
||||||
{
|
{
|
||||||
key.reset();
|
key.reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#pragma optimize("", on )
|
#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 to apply a block cipher to messages of arbitrary length in a distributed manner
|
||||||
*/
|
*/
|
||||||
class FeistelMan
|
class GhettoCipher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit FeistelMan(const Block& key);
|
explicit GhettoCipher(const Block& key);
|
||||||
explicit FeistelMan(const std::string& password);
|
explicit GhettoCipher(const std::string& password);
|
||||||
|
|
||||||
FeistelMan(const FeistelMan& other) = delete;
|
GhettoCipher(const GhettoCipher& other) = delete;
|
||||||
FeistelMan(FeistelMan&& other) noexcept = delete;
|
GhettoCipher(GhettoCipher&& other) noexcept = delete;
|
||||||
|
|
||||||
~FeistelMan();
|
~GhettoCipher();
|
||||||
|
|
||||||
//! Will set the key
|
//! Will set the key
|
||||||
void SetKey(const Block& key);
|
void SetKey(const Block& key);
|
||||||
@ -22,10 +22,10 @@ public:
|
|||||||
void SetPassword(const std::string& password);
|
void SetPassword(const std::string& password);
|
||||||
|
|
||||||
//! Will encipher a flexblock of data
|
//! 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
|
//! 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:
|
private:
|
||||||
Block key;
|
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 |
4
main.cpp
4
main.cpp
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "FeistelMan.h"
|
#include "GhettoCipher.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@ -11,7 +11,7 @@ int main()
|
|||||||
|
|
||||||
|
|
||||||
// Prepare cipher
|
// Prepare cipher
|
||||||
FeistelMan feistel("Password yo");
|
GhettoCipher feistel("Password yo");
|
||||||
|
|
||||||
|
|
||||||
// Encrypt
|
// Encrypt
|
||||||
|
Loading…
x
Reference in New Issue
Block a user