Advice on refactoring this Enigma cipher program

Hi fellow programmers! 

I was looking through a few old programs I wrote, and I came across this Enigma cipher simulator. I was wondering if you could help me refactor the algorithm, as it doesn't seem to be the most efficient method. 

Thanks for all the help! 

Lexi

PS: Source code can be found here: http://forums.codeguru.com/showthread.php?542335-Refactoring-this-Enigma-cipher-program
It's hard to read that code, there's no indentation. And I happen to be too lazy to use AStyle on it.

http://en.wikipedia.org/wiki/Indent_style

What's more, I'd have to learn the Enigma algorithm to actually help you refactor the code, and I'm much too lazy for that too. (And probably many other people feel the same.)

You'd be better off asking "hey do you see anything obviously wrong in my code?".
Well I do: it's using namespace std; in a header.

http://www.parashift.com/c++-faq/using-namespace-std.html

Also, you could rewrite Enigma::plugboard() to use switch() instead of that if()-else-if() centipede (although this merely removes the noise from the code and makes it easier to read, so technically it doesn't improve the program).

1
2
3
4
5
6
7
8
9
10
11
char Enigma::plugboard(char Char)
{
    switch (Char)
    {
        case 'A': return '0';
        case 'B': return 'Q';
        case 'C': return 'W';
        case 'D': return 'E';
        // ...
    }
}

I guess the formatting I had somehow got removed.

The Enigma algorithm is here: http://crypto.stackexchange.com/questions/3934/could-the-enigma-algorithm-be-classified-as-a-feistel-network

Lexi
Topic archived. No new replies allowed.