R
Robert Bachmann
Two years I wrote a simple cesar encryption program, it worked but it
relied on ASCII.
So today I tried to make an portable cesar encryption.
Please tell me if the code below is really protable.
Thanks in advance.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <locale.h>
char
letters_a_z[] = "zabcdefghijklmnopqrstuvwxy",
letters_A_Z[] = "ZABCDEFGHIJKLMNOPQRSTUVWXY",
letters_a_z_rot[] = "abcdefghijklmnopqrstuvwxyz",
letters_A_Z_rot[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main (void)
{
int ch;
setlocale (LC_CTYPE, "C");
while ((ch = getc (stdin)) != EOF)
{
if (isupper (ch))
ch = letters_A_Z_rot[strchr (letters_A_Z, ch) - letters_A_Z];
else if (islower (ch))
ch = letters_a_z_rot[strchr (letters_a_z, ch) - letters_a_z];
putc (ch, stdout);
}
return 0;
}
relied on ASCII.
So today I tried to make an portable cesar encryption.
Please tell me if the code below is really protable.
Thanks in advance.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <locale.h>
char
letters_a_z[] = "zabcdefghijklmnopqrstuvwxy",
letters_A_Z[] = "ZABCDEFGHIJKLMNOPQRSTUVWXY",
letters_a_z_rot[] = "abcdefghijklmnopqrstuvwxyz",
letters_A_Z_rot[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main (void)
{
int ch;
setlocale (LC_CTYPE, "C");
while ((ch = getc (stdin)) != EOF)
{
if (isupper (ch))
ch = letters_A_Z_rot[strchr (letters_A_Z, ch) - letters_A_Z];
else if (islower (ch))
ch = letters_a_z_rot[strchr (letters_a_z, ch) - letters_a_z];
putc (ch, stdout);
}
return 0;
}