annotate enigma/enigma_utils.h @ 13:b9d124a15926

To improve cache performance, the enigma machine rotors are now stored together with the reflector in a vector.
author Brian Neal <bgneal@gmail.com>
date Mon, 02 Jul 2012 19:14:36 -0500
parents 424111a36ed7
children
rev   line source
bgneal@1 1 #ifndef CPP_ENIGMA_ENIGMA_UTILS_H
bgneal@1 2 #define CPP_ENIGMA_ENIGMA_UTILS_H
bgneal@1 3 // Copyright (C) 2012 by Brian Neal.
bgneal@1 4 // This file is part of Cpp-Enigma, the Enigma Machine simulation.
bgneal@1 5 // Cpp-Enigma is released under the MIT License (see License.txt).
bgneal@1 6 //
bgneal@1 7 // enigma_utils.h - This file contains common functions used throughout Cpp-Enigma.
bgneal@1 8
bgneal@4 9 #include <string>
bgneal@4 10
bgneal@1 11 namespace enigma
bgneal@1 12 {
bgneal@1 13 // This version of mod acts like Python's with respect to negative dividends.
bgneal@1 14 inline int alpha_mod(int dividend)
bgneal@1 15 {
bgneal@1 16 if (dividend < 0)
bgneal@1 17 {
bgneal@1 18 dividend += 26;
bgneal@1 19 }
bgneal@1 20 return dividend % 26;
bgneal@1 21 }
bgneal@4 22
bgneal@4 23 // Removes spaces from a string and returns the resulting string:
bgneal@4 24 std::string remove_spaces(const std::string& s);
bgneal@12 25
bgneal@12 26 // Removes spaces & converts to signal numbers:
bgneal@12 27 std::string preprocess_ciphertext(const std::string& s);
bgneal@1 28 }
bgneal@1 29
bgneal@1 30 #endif