User definable letter swapping

P

Protoman

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!!!!
 
B

Bjoern Doebel

Protoman said:
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
 
J

Jacek Dziedzic

Protoman said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top