Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Simple Caesar cypher algorithm
- * Preserves case and non-alpha characters
- * by The Lightning Stalker
- */
- #include <stdio.h>
- #include <ctype.h>
- #define ALPHA 26 // letters in alphabet
- #define CONVBASE 7 // conversion base
- #define COMPLEMENT ALPHA - CONVBASE // conversion complement
- #define CHARLMIN *"a" + CONVBASE // smallest char without rollover
- #define CHARUMIN *"A" + CONVBASE // . . .
- static const char stringin[] = "Joyvtl Jvbuayf"; // string to convert
- int main (int argc, char **argv)
- {
- int c;
- char stringout[256];
- for (c = 0; c < sizeof(stringin); c++)
- {
- if (isalpha(stringin[c]))
- if (islower(stringin[c]))
- if (stringin[c] >= CHARLMIN)
- stringout[c] = stringin[c] - CONVBASE;
- else
- stringout[c] = stringin[c] + COMPLEMENT;
- else
- if (stringin[c] >= CHARUMIN)
- stringout[c] = stringin[c] - CONVBASE;
- else
- stringout[c] = stringin[c] + COMPLEMENT;
- else
- stringout[c] = stringin[c];
- }
- printf("%s\n", stringout);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement