(I got here through http://codereview.stackexchange.com , so I still wear a code review hat).
With code that manipulates letters, itβs easier for me to understand if it uses the actual letters in the source, rather than numeric codes. Therefore, I recommend changing
cipher[i] += (shift - 25);
to something like
cipher[i] += (shift - ('Z' - 'A'));
Most people making caesar ciphers only convert letters and omit punctuation, numbers, spaces, etc. without changes. You might consider including a standard character library.
#include <ctype.h>
and using the functions isalpha (), islower (), isupper () - in particular, changing
if ((cipher[i]) >= 'A' && (cipher[i]) <= 'Z') {
to something like
if (isupper(cipher[i])) {
.
source share