annotate enigma/examples/example1.cpp @ 19:1a5a0a3da1ba

Added tag 0.1 for changeset aa7a4298d609
author Brian Neal <bgneal@gmail.com>
date Wed, 11 Jul 2012 20:19:41 -0500
parents aa7a4298d609
children
rev   line source
bgneal@18 1 // Copyright (C) 2012 by Brian Neal.
bgneal@18 2 // This file is part of Cpp-Enigma, the Enigma Machine simulation.
bgneal@18 3 // Cpp-Enigma is released under the MIT License (see License.txt).
bgneal@18 4 //
bgneal@18 5 // example1.cpp - Quick example program showing usage.
bgneal@18 6
bgneal@18 7 #include <iostream>
bgneal@18 8 #include <string>
bgneal@18 9 #include "machine.h"
bgneal@18 10
bgneal@18 11 using namespace enigma;
bgneal@18 12
bgneal@18 13 int main()
bgneal@18 14 {
bgneal@18 15 // setup machine according to specs from a key sheet:
bgneal@18 16
bgneal@18 17 enigma_machine em({"II", "IV", "V"}, {1, 20, 11}, "B",
bgneal@18 18 "AV BS CG DL FU HZ IN KM OW RX");
bgneal@18 19
bgneal@18 20 // set initial rotor starting position
bgneal@18 21 em.set_display("WXC");
bgneal@18 22
bgneal@18 23 // decrypt the message key
bgneal@18 24 const std::string msg_key = em.process_text("KCH");
bgneal@18 25
bgneal@18 26 // decrypt the ciphertext with the unencrypted message key
bgneal@18 27 em.set_display(msg_key);
bgneal@18 28
bgneal@18 29 const std::string ciphertext("NIBLFMYMLLUFWCASCSSNVHAZ");
bgneal@18 30 const std::string plaintext(em.process_text(ciphertext));
bgneal@18 31
bgneal@18 32 std::cout << plaintext << std::endl;
bgneal@18 33 return 0;
bgneal@18 34 }