Re: Mathematics of the Enigma cipher?
- From: "DarkProtoman" <Protoman2050@xxxxxxxxx>
- Date: 30 Dec 2006 13:19:05 -0800
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!
.
- Follow-Ups:
- Re: Mathematics of the Enigma cipher?
- From: Arthur J. O'Dwyer
- Re: Mathematics of the Enigma cipher?
- References:
- Re: Mathematics of the Enigma cipher?
- From: CBFalconer
- Re: Mathematics of the Enigma cipher?
- Prev by Date: Re: Hash
- Next by Date: Re: Worst case execution time problem
- Previous by thread: Re: Mathematics of the Enigma cipher?
- Next by thread: Re: Mathematics of the Enigma cipher?
- Index(es):
Relevant Pages
|