J
James Kanze
Protoman wrote in message...
Simpler than a five line character translator? Good luck with that.
Well, character translation per se is usually only one line:
char translated = translationMap[ original ] ;
The real question, however, is: why a 36 character encoder? Why
not 256 (or more correctly, UCHAR_MAX+1)?
For the rest, there's a complete implementation of encode/decode
using a Enigma machine at my site
(http://kanze.james.neuf.fr/code-en.html, the executable
"crypt"). From the man page for it: "Isn't really useful for
anything. It's not secure enough for real encryption, and is a
lot more complicated than a simple rot13 for the cases where it
would be sufficient." But he's welcome to study it, and even
copy anything in it he wants.
Actually, it's only a three line function if you pass in the string refs.
char plugboard( char Char, std::string const &Values,
std::string const &Characters ){
std::size_t index( Characters.find( Char ) );
if( std::string::npos == index ){ return ' ';}
return Values.at( index );
}
Wouldn't it be more idiomatic to define a Translator functional
object, and let the user use std::transform? (It's certainly
more fashionable. You just aren't "in" unless you can work in
some templates and the standard algorithms
better solution is, of course, a different question.)