Be warned, the implementation is vulnerable to side-channel attacks. Please avoid using it to encode secrets. I would suggest using libsodium instead https://libsodium.gitbook.io/doc/helpers - although it does not offer a base32 variant.
#include <ctype.h>
#define IFTHENELSE(c, t, e) ((-(!!(c)) & (t)) | (-(!(c)) & (e)))
unsigned char
mod26 (unsigned char x)
{
x -= IFTHENELSE(x >= 26 * 4,
26 * 4,
0);
x -= IFTHENELSE(x >= 26 * 2,
26 * 2,
0);
x -= IFTHENELSE(x >= 26 * 2,
26 * 2,
0);
x -= IFTHENELSE(x >= 26,
26,
0);
return x;
}
unsigned char
rot13 (unsigned char x)
{
return IFTHENELSE(islower(x), mod26(x - 'a' + 13) + 'a',
IFTHENELSE(isupper(x), mod26(x - 'A' + 13) + 'A',
x));
}
implementing base32h should be much easier as you do not need to perform mod with a non-power of 2.