/* Author: Pate Williams (c) 1997 Exercise III.1.3 "In the 27-letter alphabet (with blank = 26), use the affine enciphering transformation with key a = 13, b = 9 to encipher the message "HELP ME". -Neal Koblitz- See "A Course in Number Theory and Cryptography" by Neal Koblitz second edition page 62. */ #include #include int main(void) { char plaintext[16] = "HELP ME"; long a = 13, b = 9, c, i, p = 27; printf("%s\n", plaintext); for (i = 0; i < strlen(plaintext); i++) { c = plaintext[i]; if (c == ' ') c = 26; else c -= 'A'; c = (a * c + b) % p; printf("%c", c + 'A'); } printf("\n"); return 0; }