Caesar Cipher
CSC-327 · Semester V · Cryptography
#include <stdio.h> #include <string.h> char caesar(char c, int shift) { if (c >= 'a' && c <= 'z') return 'a' + (c - 'a' + shift) % 26; if (c >= 'A' && c <= 'Z') return 'A' + (c - 'A' + shift) % 26; return c; } int main() { int shift; printf("Enter shift: "); scanf("%d", &shift); string msg; printf("Enter message: "); scanf("%s", &msg); for (int i = 0; msg[i] != 0; i++) { printf("%c", caesar(msg[i], shift)); } printf("\n"); return 0; }
Write some code, then press Run. Stdout and errors appear here.