Added utilities to work with files

This commit is contained in:
Leonetienne
2021-12-06 01:33:55 +01:00
parent a322e9ea98
commit 65f80b5d2d
6 changed files with 74 additions and 21 deletions

View File

@@ -41,7 +41,7 @@ void FeistelMan::SetPassword(const std::string& password)
return;
}
Flexblock FeistelMan::Encipher(const Flexblock& data) const
Flexblock FeistelMan::Encipher(const Flexblock& data, bool printReports) const
{
// Split cleartext into blocks
std::vector<Block> blocks;
@@ -56,6 +56,10 @@ Flexblock FeistelMan::Encipher(const Flexblock& data) 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))
std::cout << "Encrypting... (Block " << i << " / " << blocks.size() << " - " << ((float)i*100 / blocks.size()) << "\%)" << std::endl;
const Block& lastBlock = (i>0) ? blocks[i-1] : emptyBlock;
blocks[i] = feistel.Encipher(blocks[i] ^ lastBlock);
}
@@ -69,7 +73,7 @@ Flexblock FeistelMan::Encipher(const Flexblock& data) const
return ss.str();
}
Flexblock FeistelMan::Decipher(const Flexblock& data) const
Flexblock FeistelMan::Decipher(const Flexblock& data, bool printReports) const
{
// Split ciphertext into blocks
std::vector<Block> blocks;
@@ -87,6 +91,10 @@ Flexblock FeistelMan::Decipher(const Flexblock& data) 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))
std::cout << "Decrypting... (Block " << i << " / " << blocks.size() << " - " << ((float)i*100/ blocks.size()) << "\%)" << std::endl;
Block tmpCopy = blocks[i];
blocks[i] = feistel.Decipher(blocks[i]) ^ lastBlock;