#include #include #include void caesar_shift(char *s, int shift) { int delta = ((shift % 26) + 26) % 26; for (int i = 0; s[i] != '\0'; i++) { unsigned char c = (unsigned char)s[i]; if (isupper(c)) { s[i] = 'A' + (c - 'A' + delta) % 26; } else if (islower(c)) { s[i] = 'a' + (c - 'a' + delta) % 26; } } } int simple_hash(const char *s) { int h = 0; for (int i = 0; s[i] != '\0'; i++) { h = (h + (unsigned char)s[i]) % 256; } return h; } int main(void) { char buf[64] = "Transfer funds now"; int h = simple_hash(buf); printf("plaintext: %s\n", buf); printf("hash: %d\n", h); caesar_shift(buf, 3); printf("ciphertext: %s\n", buf); caesar_shift(buf, -3); printf("decrypted: %s hash_match=%s\n", buf, simple_hash(buf) == h ? "yes" : "no"); caesar_shift(buf, 3); buf[4] = 'X'; caesar_shift(buf, -3); printf("tampered decrypt: %s hash_match=%s\n", buf, simple_hash(buf) == h ? "yes" : "no"); return 0; }