Mercurial > public > cpp-enigma
diff enigma/examples/example1.cpp @ 18:aa7a4298d609 0.1
Added a LICENSE, README, and an example.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 11 Jul 2012 20:19:35 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/enigma/examples/example1.cpp Wed Jul 11 20:19:35 2012 -0500 @@ -0,0 +1,34 @@ +// Copyright (C) 2012 by Brian Neal. +// This file is part of Cpp-Enigma, the Enigma Machine simulation. +// Cpp-Enigma is released under the MIT License (see License.txt). +// +// example1.cpp - Quick example program showing usage. + +#include <iostream> +#include <string> +#include "machine.h" + +using namespace enigma; + +int main() +{ + // setup machine according to specs from a key sheet: + + enigma_machine em({"II", "IV", "V"}, {1, 20, 11}, "B", + "AV BS CG DL FU HZ IN KM OW RX"); + + // set initial rotor starting position + em.set_display("WXC"); + + // decrypt the message key + const std::string msg_key = em.process_text("KCH"); + + // decrypt the ciphertext with the unencrypted message key + em.set_display(msg_key); + + const std::string ciphertext("NIBLFMYMLLUFWCASCSSNVHAZ"); + const std::string plaintext(em.process_text(ciphertext)); + + std::cout << plaintext << std::endl; + return 0; +}