Exemplo n.º 1
0
int main(int argc, char *argv[])
{
  CommandLineInfo info;
  processCommandLine(argc,argv,info);
  
  std::string in{""};
  char in_char{'x'};

  if(info.input_file_name == "")
    {
      while(std::cin >> in_char) // Builds output from input
	{
	  in += transformChar(in_char);
	}
    }
  else
    {
Exemplo n.º 2
0
int main(const int argc, const char*argv[])
{
  std::string out{""};    
  char in_char{'x'};
  std::cout << "insert a string" << "\n";
  //loop on input string characters
  while (std::cin >> in_char){

    std::cout << "in_char = " << in_char << "\n";
    out = transformChar(in_char);
    std::cout << " ";
  }
  std::cout << "\n";
  std::cout << "input string = " << out << "\n";
  std::cout << "insert cipher shift" << "\n";
  for (int i = 0; i < out.size(); i++){

    out[i] = substituteChar(out[i], shift);
  }

std::cout << "ciphered string = " << out << "\n";
//! Test that Catch works
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

#include "TransformChar.hpp"

TEST_CASE("Characters are uppercased", "[alphanumeric]"){
   REQUIRE(transformChar('a') == "A");
   REQUIRE(transformChar('b') == "B");
   REQUIRE(transformChar('c') == "C");
   REQUIRE(transformChar('d') == "D");
   REQUIRE(transformChar('e') == "E");
   REQUIRE(transformChar('f') == "F");
   REQUIRE(transformChar('g') == "G");
   REQUIRE(transformChar('h') == "H");
   REQUIRE(transformChar('i') == "I");
   REQUIRE(transformChar('j') == "J");
   REQUIRE(transformChar('k') == "K");
   REQUIRE(transformChar('l') == "L");
   REQUIRE(transformChar('m') == "M");
   REQUIRE(transformChar('n') == "N");
   REQUIRE(transformChar('o') == "O");
   REQUIRE(transformChar('p') == "P");
   REQUIRE(transformChar('q') == "Q");
   REQUIRE(transformChar('r') == "R");
   REQUIRE(transformChar('s') == "S");
   REQUIRE(transformChar('t') == "T");
   REQUIRE(transformChar('u') == "U");
   REQUIRE(transformChar('v') == "V");
   REQUIRE(transformChar('w') == "W");
   REQUIRE(transformChar('x') == "X");
Exemplo n.º 4
0
int main(int argc, char* argv[])
{
   //testCipher();
   CommandLineArguments args{false, false, false, "", "", "", ""};
   int retCode = processCommandLine(argc, argv, args);
   
   if(retCode != 0)
   {
	   return retCode;
   }
   
   // Use standard input by default
   std::ifstream inputStream{};
   if(!args.inputFilename.empty())
   {  // Try to use the input file
      inputStream.open(args.inputFilename);
      if(!inputStream.good())
      {
         std::cout << "Error: Could not open " << args.inputFilename << std::endl;
         return 1;
      }
   }

   std::ofstream outputStream{};
   if(!args.outputFilename.empty())
   {  // Try to use the output file
      outputStream.open(args.outputFilename);
      if(!outputStream.good())
      {
         std::cout << "Error: Could not open " << args.outputFilename << std::endl;
         return 1;
      }
   }
     
   std::string text = processInput(
      args.inputFilename.empty() ? std::cin : inputStream);

   std::string input{};
   for(char c : text)
   {
	   input.append(transformChar(c));
   }

   std::unique_ptr<Cipher> cipher;
   if(args.cipher == "caesar")
   {
      cipher = cipherFactory(CipherTypes::CAESAR);
   }
   else if(args.cipher == "playfair")
   {
      cipher = cipherFactory(CipherTypes::PLAYFAIR);
   }
   else if(args.cipher == "vigenere")
   {
      cipher = cipherFactory(CipherTypes::VIGENERE);
   }
   
   (*cipher).setKey(args.key);
   if(args.encrypt)
   {
      std::string ciphertext = (*cipher).encode(input);
      processOutput(
         args.outputFilename.empty() ? std::cout : outputStream,
         ciphertext);
   }
   else
   {
      std::string plaintext = (*cipher).decode(input);
      processOutput(
         args.outputFilename.empty() ? std::cout : outputStream,
         plaintext);      
   }
  
   return 0;
}
Exemplo n.º 5
0
int main(int argc,char* argv[])
  
{
  bool helpBool {false};
  float versionNumber{4.5};
  bool versionBool {false};
  
  for (int a=0; a< argc; a++)
    {
      std::string tempString = argv[a];
	
      //   std::cout << tempString<<std::endl;

      if ((tempString=="--help")||(tempString=="-h"))
	{
	  helpBool=true;
	}
      
      if (tempString=="-o")
	{
	  std::cout<< argv[a+1]<<std::endl;
	}

      if (tempString=="-i")
	{
	  std::cout<< argv[a+1]<<std::endl;
	}

      if ((tempString=="--version")||(tempString=="-v"))
	{
	  versionBool=true;
	}

    }
  if (versionBool==true)
    {
      std::cout<<"Version number is: "<< versionNumber<<std::endl;
    }  
      
  if (helpBool==true)
    {
      std::cout<< "Here to help"<<std::endl;
    }

  
 
 

  
         
  
  std::string thing;
  char in_char{'x'};
  
  while (std::cin>> in_char)
    {
      thing = thing + transformChar(in_char);

    }

  std::cout << thing;
  return 0;
}