Protoman wrote:
How would I write a user defnable letter swapping algorithm? I've
written an Enigma encrypting program, and I need to redo the plugboard
function. Right now, the letter swapping is fixed. I need to allow the
user to swap 23 pairs of characters. As you may have guessed, I'm using
an alphabet of 36 characters, A-Z and 0-9. Thanks!!!!
The easy way:
Have two const strings -- one with the cleartext alphabet,
the other with the ciphertext alphabet. Then, whenever the
user enters a character, find it in the cleartext alphabet,
remember the position 'i' at which you found it, return to
the user the i-th character of the cipherthext alphabet.
The more-difficult way:
Use a std::map, indexed by the cleartext characters
in which you store ciphertext characters.
If you want these alphabets to be changed without
having to recompile the program, follow Bjoern's suggestion.
HTH,
- J.
HTH,
- J.