This repository has been archived on 2026-05-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2026-02-09 03:43:16 +01:00

59 lines
970 B
C

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
char shift(char c, int by)
{
int start = 0;
if(c >= 'a' && c <= 'z')
{
start = 'a';
}
else if(c >= 'A' && c <= 'Z')
{
start = 'A';
}
else return c;
c -= start;
c += by;
c %= 26;
return c + start;
}
char *reverse_shifted(char *input, int by)
{
if(!input)
{
return NULL;
}
int len = strlen(input);
char *res = calloc(len, sizeof(char));
if(!res)
{
return NULL;
}
int start = 0;
int end = len + 1;
for (int i = 0; i < len; i++)
{
char val = input[end--];
val = shift(val, by);
res[start++] = val;
}
return res;
}
int main(void)
{
char *test1 = "!qxsbdc k cs csrd";
char *res1 = reverse_shifted(test1, 42);
if(!res1)
{
return EXIT_FAILURE;
}
printf("%s",res1);
puts(res1);
free(res1);
return EXIT_SUCCESS;
}