#include <stdio.h>
#include <string.h>
int main()
{
char s[100000], op[100000];
int k, i;
/*
's' = the message to be encrypted
'op' = encrypted message output
'k' = store shift value
'i' = looping variable
*/
// Accept the message to be encrypted.
gets(s);
// Accept the shift value (the value by which the characters are to be shifted).
scanf("%d", & k);
for (i = 0; i < strlen(s); i++)
{
//Check if the character is UPPERCASE or not
if (s[i] >= 65 && s[i] <= 90)
/*
Check if the shifted value's ascii character is greater than 90
(which is invalid, because there is no UPPERCASE alphabet greater than Z)
*/
if ((s[i] + (k % 26)) > 90)
/*
If yes, subtract 90 from the obtained sum (which will give us the normal shift value),
and add it to 64 because after Z, the cycle should begin again from A.
*/
op[i] = 64 + ((s[i] + (k % 26)) - 90);
else
// If no, then proceed normally
op[i] = s[i] + (k % 26);
}
//Check if the character is lowercase or not
else if (s[i] >= 97 && s[i] <= 122)
{
/*
Check if the shifted value's ascii character is greater than 122
(which is invalid, because there is no lowercase alphabet greater than z).
*/
if ((s[i] + (k % 26)) > 122)
/*
If yes, subtract 122 from the obtained sum (which will give us the normal shift value),
and add it to 96 because after Z, the cycle should begin again from a.
*/
op[i] = 96 + ((s[i] + (k % 26)) - 122);
else
// If no, then proceed normally
op[i] = s[i] + (k % 26);
}
//Check if the character is a numeric digit or not.
else if (s[i] >= 48 && s[i] <= 57)
{
/*
Check if the shifted value's ascii character is greater than 57
(which is invalid, because there is no decimal digit greater than 9)
*/
if ((s[i] + (k % 10)) > 57)
/*
If yes, subtract 57 from the obtained sum (which will give us the normal shift value),
and add it to 47 because after 9, the cycle should begin again from 0.
*/
op[i] = 47 + ((s[i] + (k % 10)) - 57);
else
// If no, proceed normally
op[i] = s[i] + (k % 10);
}
else
{
//ignore (i.e don't shift) any other kind of character (which means special characters)
op[i] = s[i];
}
// Print the output (the encrypted message)
puts(op);
return 0;
}