Re: Mathematics of the Enigma cipher?




CBFalconer wrote:
Michael Olea wrote:
CBFalconer wrote:
DarkProtoman wrote:

... snip ...
{
memcpy(Alphabet,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",36);
}
int GetCurrentPos(){return CurPos;}
int CharacterMap(char Char)
{
if(Char='A')
return 0;
else if(Char='B')
return 1;

... snip ...

else if(Char='7')
return 34;
else if(Char='8')
return 35;
else if(Char='9')
return 36;
}

why all this code? Try (in C):

static const char *alphabet =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const char *p;

if (p = strchr(alphabet, char)) return (p - alphabet) + 1;
else return 0; /* detect not in alphabet */

with which you can easily modify the alphabet in one place. Hint:
eschew code that requires various areas to agree if any change is
desired.

There is no need to store a string or loop over it, since in ASCII
uppercase alpha is contiguous, as are digits. So a version that
checks for invalid input:

Just as all computers are not x86s, all char sets are not ASCII.
Do you want your code to work, or do you want it to fail
mysteriously?

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

No one has given me any ideas of how to implement the reflector yet!

.



Relevant Pages