Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) CodeBreaker

 

CodeBreaker is a tool to do code breaking

 

 

 

 

 

Downloads

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./ToolCodeBreaker/ToolCodeBreakerConsole.pro

 

include(../../ConsoleApplication.pri)
include(../../Libraries/Boost.pri)
include(../../Libraries/GeneralConsole.pri)

include(../../Classes/CppCaesarCipher/CppCaesarCipher.pri)
include(../../Classes/CppCodeBreaker/CppCodeBreaker.pri)
include(../../Classes/CppLoopReader/CppLoopReader.pri)
include(../../Classes/CppVigenereCipher/CppVigenereCipher.pri)
include(../../Tools/ToolCaesarCipher/ToolCaesarCipherConsole.pri)
include(../../Tools/ToolCodeBreaker/ToolCodeBreakerConsole.pri)
include(../../Tools/ToolVigenereCipher/ToolVigenereCipherConsole.pri)

SOURCES += main.cpp

 

 

 

 

 

Qt project file: ./ToolCodeBreaker/ToolCodeBreakerDesktop.pro

 

include(../../DesktopApplication.pri)
include(../../Libraries/Boost.pri)
include(../../Libraries/GeneralConsole.pri)
include(../../Libraries/GeneralDesktop.pri)

include(../../Classes/CppCaesarCipher/CppCaesarCipher.pri)
include(../../Classes/CppCodeBreaker/CppCodeBreaker.pri)
include(../../Classes/CppLoopReader/CppLoopReader.pri)
include(../../Classes/CppVigenereCipher/CppVigenereCipher.pri)

include(../../Tools/ToolCaesarCipher/ToolCaesarCipherDesktop.pri)
include(../../Tools/ToolVigenereCipher/ToolVigenereCipherDesktop.pri)

include(../../Tools/ToolCodeBreaker/ToolCodeBreakerDesktop.pri)

SOURCES += qtmain.cpp

 

 

 

 

 

Qt project file: ./ToolCodeBreaker/ToolCodeBreakerWebsite.pro

 

include(../../WebApplication.pri)
include(../../Libraries/Boost.pri)
include(../../Libraries/Wt.pri)
include(../../Libraries/GeneralConsole.pri)
include(../../Libraries/GeneralWeb.pri)


include(../../Classes/CppCaesarCipher/CppCaesarCipher.pri)
include(../../Classes/CppVigenereCipher/CppVigenereCipher.pri)
include(../../Classes/CppLoopReader/CppLoopReader.pri)
include(../../Tools/ToolCodeBreaker/ToolCodeBreakerWebsite.pri)

SOURCES += wtmain.cpp

 

 

 

 

 

./ToolCodeBreaker/ToolCodeBreakerConsole.pri

 

INCLUDEPATH += \
    ../../Tools/ToolCodeBreaker

SOURCES += \
    ../../Tools/ToolCodeBreaker/codebreakermaindialog.cpp \
    ../../Tools/ToolCodeBreaker/codebreakermenudialog.cpp

HEADERS += \
    ../../Tools/ToolCodeBreaker/codebreakermaindialog.h \
    ../../Tools/ToolCodeBreaker/codebreakermenudialog.h

OTHER_FILES += \
    ../../Tools/ToolCodeBreaker/Licence.txt

 

 

 

 

 

./ToolCodeBreaker/ToolCodeBreakerDesktop.pri

 

include(../../Tools/ToolCodeBreaker/ToolCodeBreakerConsole.pri)

SOURCES += \
  ../../Tools/ToolCodeBreaker/qtcodebreakermaindialog.cpp

HEADERS += \
  ../../Tools/ToolCodeBreaker/qtcodebreakermaindialog.h

FORMS += \
  ../../Tools/ToolCodeBreaker/qtcodebreakermaindialog.ui

RESOURCES += \
  ../../Tools/ToolCodeBreaker/ToolCodeBreaker.qrc

OTHER_FILES += \
  ../../Tools/ToolCodeBreaker/Licence.txt

 

 

 

 

 

./ToolCodeBreaker/ToolCodeBreakerWebsite.pri

 

include(../../Tools/ToolCodeBreaker/ToolCodeBreakerConsole.pri)

SOURCES +=
HEADERS +=

 

 

 

 

 

./ToolCodeBreaker/codebreakermaindialog.h

 

//---------------------------------------------------------------------------
/*
CodeBreaker, code breaking tool
Copyright (C) 2014-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolCodeBreaker.htm
//---------------------------------------------------------------------------
#ifndef CODEBREAKERMAINDIALOG_H
#define CODEBREAKERMAINDIALOG_H

#include <string>
#include <vector>
#include <boost/scoped_ptr.hpp>
#include "about.h"
#include "codebreaker.h"

namespace ribi {

struct CodeBreakerMainDialog
{
  CodeBreakerMainDialog() noexcept;

  std::string GetAdvice() const noexcept;

  const std::string& GetEncryptedText() const noexcept { return m_encrypted_text; }
  void SetEncryptedText(const std::string& s) noexcept;

  private:
  boost::scoped_ptr<CodeBreaker> m_codebreaker;
  std::string m_encrypted_text;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

} //~namespace ribi

#endif // CODEBREAKERMAINDIALOG_H

 

 

 

 

 

./ToolCodeBreaker/codebreakermaindialog.cpp

 

//---------------------------------------------------------------------------
/*
CodeBreaker, code breaking tool
Copyright (C) 2014-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolCodeBreaker.htm
//---------------------------------------------------------------------------
#include "codebreakermaindialog.h"

#include <cassert>
#include <sstream>

#include "testtimer.h"
#include "trace.h"

ribi::CodeBreakerMainDialog::CodeBreakerMainDialog() noexcept
  : m_codebreaker(new CodeBreaker),
    m_encrypted_text{}
{
  #ifndef NDEBUG
  Test();
  #endif
}

std::string ribi::CodeBreakerMainDialog::GetAdvice() const noexcept
{
  std::stringstream s;



  return s.str();
}

void ribi::CodeBreakerMainDialog::SetEncryptedText(const std::string& s) noexcept
{
  m_encrypted_text = s;
}

#ifndef NDEBUG
void ribi::CodeBreakerMainDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
  {
    CodeBreaker b;
    CodeBreakerMainDialog d;
    d.SetEncryptedText(b.GetExampleEnglish());
  }
}
#endif

 

 

 

 

 

./ToolCodeBreaker/codebreakermenudialog.h

 

//---------------------------------------------------------------------------
/*
CodeBreaker, code breaking tool
Copyright (C) 2014-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolCodeBreaker.htm
//---------------------------------------------------------------------------
#ifndef CODEBREAKERMENUDIALOG_H
#define CODEBREAKERMENUDIALOG_H

#include <string>
#include <vector>
#include "about.h"
#include "help.h"
#include "menudialog.h"
#include "richelbilderbeekprogram.h"

namespace ribi {

struct CodeBreakerMenuDialog final : public MenuDialog
{
  About GetAbout() const noexcept override;
  Help GetHelp() const noexcept override;
  boost::shared_ptr<const Program> GetProgram() const noexcept override;
  std::string GetVersion() const noexcept override;
  std::vector<std::string> GetVersionHistory() const noexcept override;

  private:
  int ExecuteSpecific(const std::vector<std::string>& argv) noexcept override;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

} //~namespace ribi

#endif // CODEBREAKERMENUDIALOG_H

 

 

 

 

 

./ToolCodeBreaker/codebreakermenudialog.cpp

 

//---------------------------------------------------------------------------
/*
CodeBreaker, code breaking tool
Copyright (C) 2014-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolCodeBreaker.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include "codebreakermenudialog.h"

#include <cassert>
#include <iostream>
#include <boost/lexical_cast.hpp>

#include "caesarcipher.h"
#include "caesarciphermenudialog.h"
#include "codebreaker.h"
#include "codebreakermaindialog.h"
#include "loopreader.h"
#include "trace.h"
#include "testtimer.h"
#include "vigenerecipher.h"
#include "vigenereciphermenudialog.h"
#pragma GCC diagnostic pop

int ribi::CodeBreakerMenuDialog::ExecuteSpecific(const std::vector<std::string>& argv) noexcept
{
  #ifndef NDEBUG
  Test();
  #endif

  const int argc = static_cast<int>(argv.size());
  if (argc == 1)
  {
    std::cout << GetHelp() << '\n';
    return 1;
  }
  bool is_silent = false;
  for (int i=0; i!=argc; ++i)
  {
    if (argv[i] == "-s" || argv[i] == "--silence")
    {
      is_silent = true;
    }
  }

  //Determine if plaintext is supplied, if yes: execute
  for (int i=0; i!=argc-1; ++i) //-1 because the next argument will be used
  {
    if (argv[i] == "-t" || argv[i] == "--text")
    {
      const std::string plaintext = argv[i + 1];
      CodeBreakerMainDialog d;
      d.SetEncryptedText(plaintext);
      if (!is_silent) { std::cout << d.GetAdvice() << '\n'; }
      return 0;
    }
  }
  return 0;
}

ribi::About ribi::CodeBreakerMenuDialog::GetAbout() const noexcept
{
  About a(
    "Richel Bilderbeek",
    "CodeBreaker",
    "code breaking tool",
    "the 4th of April 2014",
    "2014-2014",
    "http://www.richelbilderbeek.nl/ToolCodeBreaker.htm",
    GetVersion(),
    GetVersionHistory());
  a.AddLibrary("CaesarCipher (class) version: " + CaesarCipher::GetVersion());
  a.AddLibrary("CaesarCipher (tool) version: " + CaesarCipherMenuDialog().GetVersion());
  a.AddLibrary("CodeBreaker (class) version: " + CodeBreaker::GetVersion());
  a.AddLibrary("LoopReader version: " + LoopReader<int>::GetVersion());
  a.AddLibrary("VigenereCipher (class) version: " + VigenereCipher::GetVersion());
  a.AddLibrary("VigenereCipher (tool) version: " + VigenereCipherMenuDialog().GetVersion());
  return a;
}

ribi::Help ribi::CodeBreakerMenuDialog::GetHelp() const noexcept
{
  return ribi::Help(
    this->GetAbout().GetFileTitle(),
    this->GetAbout().GetFileDescription(),
    {
      Help::Option('c',"cipher","the ciphertext, will be decrypted"),
      Help::Option('k',"key","the encryption key, a number, zero by default"),
      Help::Option('t',"text","the plaintext, will be encrypted"),
      Help::Option('s',"silent","silence output, used for debugging")
    },
    {
      "CodeBreaker -k 123 --text \"helloworld\"",
      "CodeBreaker -k 123 --cipher \"helloworld\""
    }
  );
}

boost::shared_ptr<const ribi::Program> ribi::CodeBreakerMenuDialog::GetProgram() const noexcept
{
  const boost::shared_ptr<const ribi::Program> p(new ProgramCodeBreaker);
  assert(p);
  return p;

}

std::string ribi::CodeBreakerMenuDialog::GetVersion() const noexcept
{
  return "1.0";
}

std::vector<std::string> ribi::CodeBreakerMenuDialog::GetVersionHistory() const noexcept
{
  return {
    "2014-04-04: Version 1.0: initial version"
  };
}

#ifndef NDEBUG
void ribi::CodeBreakerMenuDialog::Test() noexcept
{
  {
    static bool is_tested{false};
    if (is_tested) return;
    is_tested = true;
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
  {
    CodeBreakerMenuDialog d;
    d.Execute( {"CodeBreaker", "-k", "0", "--text", "helloworld", "-s" } );
    d.Execute( {"CodeBreaker", "-k", "1", "--text", "helloworld", "-s" } );
    d.Execute( {"CodeBreaker", "-k", "2", "--text", "helloworld", "-s" } );
    d.Execute( {"CodeBreaker", "-k", "123", "--cipher", "helloworld", "-s" } );
  }
}
#endif

 

 

 

 

 

./ToolCodeBreaker/main.cpp

 

//---------------------------------------------------------------------------
/*
CodeBreaker, code breaking tool
Copyright (C) 2014-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolCodeBreaker.htm
//---------------------------------------------------------------------------
#include <string>
#include <vector>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include "codebreakermenudialog.h"
#pragma GCC diagnostic pop

int main(int argc, char *argv[])
{
  const std::vector<std::string> args { ribi::MenuDialog::ConvertArguments(argc,argv) };
  ribi::CodeBreakerMenuDialog d;
  return d.Execute(args);
}

 

 

 

 

 

./ToolCodeBreaker/qtcodebreakermaindialog.h

 

#ifndef QTCODEBREAKERMAINDIALOG_H
#define QTCODEBREAKERMAINDIALOG_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <QDialog>
#pragma GCC diagnostic pop

namespace Ui {
  class QtCodeBreakerMainDialog;
}

namespace ribi {

class QtCodeBreakerMainDialog : public QDialog
{
  Q_OBJECT
  
public:
  explicit QtCodeBreakerMainDialog(QWidget *parent = 0);
  QtCodeBreakerMainDialog(const QtCodeBreakerMainDialog&) = delete;
  QtCodeBreakerMainDialog& operator=(const QtCodeBreakerMainDialog&) = delete;
  ~QtCodeBreakerMainDialog();
  
private:
  Ui::QtCodeBreakerMainDialog *ui;
};

} //~namespace ribi

#endif // QTCODEBREAKERMAINDIALOG_H

 

 

 

 

 

./ToolCodeBreaker/qtcodebreakermaindialog.cpp

 

#include "qtcodebreakermaindialog.h"

#include <cassert>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <QVBoxLayout>

#include "qtcaesarciphermaindialog.h"
#include "qtvigenereciphermaindialog.h"

#include "ui_qtcodebreakermaindialog.h"
#pragma GCC diagnostic pop

ribi::QtCodeBreakerMainDialog::QtCodeBreakerMainDialog(QWidget *parent) :
  QDialog(parent),
  ui(new Ui::QtCodeBreakerMainDialog)
{
  ui->setupUi(this);

  assert(!this->layout());
  QLayout * const layout = new QVBoxLayout;
  assert(layout);
  this->setLayout(layout);

  {
    QtCaesarCipherMainDialog * const dialog
      = new QtCaesarCipherMainDialog;
    assert(dialog);
    layout->addWidget(dialog);
  }
  {
    QtVigenereCipherMainDialog * const dialog
      = new QtVigenereCipherMainDialog;
    assert(dialog);
    layout->addWidget(dialog);
  }
}

ribi::QtCodeBreakerMainDialog::~QtCodeBreakerMainDialog()
{
  delete ui;
}

 

 

 

 

 

./ToolCodeBreaker/qtmain.cpp

 

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include "qtcodebreakermaindialog.h"
#include <QApplication>
#pragma GCC diagnostic pop

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  ribi::QtCodeBreakerMainDialog w;
  w.show();
  return a.exec();
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml