Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- int rot13(int);
- bool is_lowcase(int);
- bool is_upcase(int);
- int main(int argc, char *argv[])
- {
- int b, r;
- printf("Enter a number to see its rot13: ");
- scanf("%c", &b);
- r = (char)rot13(b);
- printf("The rot13 of %c is %c.\n", b, r);
- return 0;
- }
- int rot13(int c)
- {
- int k;
- if (is_upcase(c)) {
- if (c > 'M') {
- c -= 13;
- }
- else {
- c += 13;
- }
- }
- else if (is_lowcase(c)) {
- if (c > 'm') {
- c -= 13;
- }
- else {
- c += 13;
- }
- }
- else {
- return c;
- }
- }
- bool is_lowcase(int c)
- {
- if (c >= 'a' && c <= 'z') {
- return true;
- }
- else {
- return false;
- }
- }
- bool is_upcase(int c)
- {
- if (c >= 'A' && c <= 'Z') {
- return true;
- }
- else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement