Caesar Cipher

#include<stdio.h> #include<string.h> void gete(char *i) { char inp[100]; int len, j; gets(inp); len = strlen(inp); for (j = 0; j <= len; j++) *(i + j) = inp[j]; } int main() { char inp[100] = {0}, cdr[] = "AAEEIIOOUUAABCDFGHJKLMNPQRSTVWXYZBCaaeeiioouuaabcdfghjklmnpqrstvwxyzbc", ch; int c, i, j, len; X: printf("Enter 1 to Encode\nEnter 2 to Decode\nEnter 0 to Exit\nEnter Your Choice: "); scanf("%d",&c); if (c == 1) { printf("Enter the Text: "); gete(&inp); for (i = 0; i < len; i++) { if ((inp[i] < 65) || (inp[i] > 122) || (inp[i] > 90 && inp[i] < 97)) printf("%c", inp[i]); else for (j = 0; j < 64; j++) if (inp[i] == cdr[j]) { printf("%c", cdr[j + 2]); break; } } printf("\n"); goto X; } else if (c == 2) { printf("Enter the Text: "); for (i = 0; ch != '\n'; i++) { scanf("%c", &ch); if(ch != '\n') inp[i] = ch; } for (i = 0; i < len; i++) { if ((inp[i] < 65) || (inp[i] > 122) || (inp[i] > 90 && inp[i] < 97)) printf("%c", inp[i]); else for (j = 2; j < 68; j++) { if (j == 35) j = 37; if (inp[i] == cdr[j]) { printf("%c", cdr[j - 2]); break; } } } printf("\n"); goto X; } else if(c == 0) goto Z; else { printf("Wrong input. Try Again\n\n"); goto X; } Z: return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.