Connecting Tech Pros Worldwide Help | Site Map

User definable letter swapping

  #1  
Old January 5th, 2007, 05:55 AM
Protoman
Guest
 
Posts: n/a
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!!!!

  #2  
Old January 5th, 2007, 07:35 AM
Bjoern Doebel
Guest
 
Posts: n/a

re: User definable letter swapping


Protoman wrote:
Quote:
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!!!!
Why not put the 18 pairs (36/2!) into a file and read them at program startup?

Bjoern
  #3  
Old January 5th, 2007, 06:15 PM
Jacek Dziedzic
Guest
 
Posts: n/a

re: User definable letter swapping


Protoman wrote:
Quote:
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.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is C99 the final C? Michael B. answers 193 November 14th, 2005 04:46 PM