You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

153 lines
3.4 KiB

// License: AGPLv3 or later. https://www.gnu.org/licenses/licenses.html
#include <ctype.h>
#include <iostream>
#include <typeinfo>
#include "cfc.h"
#include "generateValue.h"
using namespace std;
driver::driver(processArguments &theProgArgs):
ProgramArguments(theProgArgs)
{
if (ProgramArguments.codewordType() == "mint")
{
Mint aMint(Mint::zeroSymbol, ProgramArguments.modulus());
processMintOrMelt(aMint);
}
else if (ProgramArguments.codewordType() == "melt")
{
Melt aMelt(Melt::zeroSymbol);
processMintOrMelt(aMelt);
}
else
{
cerr_and_exit(
2,
"unexpected",
__FILE__,
__func__,
__LINE__,
"ProgArgs.codewordType() is neither mint nor melt. Its "
+ ProgramArguments.codewordType() +'.'
);
}
}
void driver::processMint(Codebook<Codeword<Mint>> &theCodebook)
{
// adding rest of the randomly generated codewords
for (int i=1; i < ProgramArguments.codebookSize(); i++)
{
Codeword<Mint> aCodeword;
for (int j=0; j < ProgramArguments.codewordLength(); j++)
{
int randomNumber = generateMint(
ProgramArguments.randomGeneratorSeed(),
ProgramArguments.modulus()
);
Mint aMint(randomNumber, ProgramArguments.modulus());
aCodeword.push_back(aMint);
}
theCodebook.push_back(aCodeword);
}
theCodebook.Display();
}
void driver::processMelt(Codebook<Codeword<Melt>> &theCodebook)
{
// adding rest of the randomly generated codewords
for (int i=1; i < ProgramArguments.codebookSize(); i++)
{
Codeword<Melt> aCodeword;
for (int j=0; j < ProgramArguments.codewordLength(); j++)
{
char randomCharacter = generateMelt(
ProgramArguments.randomGeneratorSeed()
);
Melt aMelt(randomCharacter);
aCodeword.push_back(aMelt);
}
theCodebook.push_back(aCodeword);
}
theCodebook.Display();
}
void driver::processMint(Codebook<Codeword<Melt>> &theCodebook)
{
cerr_and_exit(
2,
"unexpected",
__FILE__,
__func__,
__LINE__,
"function called for processing Melt cases."
);
}
void driver::processMelt(Codebook<Codeword<Mint>> &theCodebook)
{
cerr_and_exit(
2,
"unexpected",
__FILE__,
__func__,
__LINE__,
"function called for processing Mint cases."
);
}
Mint::Mint(int Number, int Modulus) : modulus(Modulus)
{
if (Number < modulus and Number >= 0)
{
number = Number;
}
else if (Number > modulus)
{
number = Number%modulus;
}
else if (Number < 0)
{
}
}
int Mint::getNumber() const
{
return number;
}
int Mint::getSymbol() const
{
return getNumber();
}
int Mint::operator-(const Mint mint2) const
{
int beforeModulating = number - mint2.getNumber();
int afterModulating = modulate(beforeModulating, modulus);
return afterModulating;
}
Melt::Melt(char Character)
{
character = tolower(Character);
}
char Melt::getCharacter() const
{
return character;
}
char Melt::getSymbol() const
{
return getCharacter();
}
int Melt::operator-(const Melt melt2) const
{
return (character != melt2.getCharacter());
}