//加密:e(x)=(ax+b)modm;
//解密:d(y)=a-1(y-b)modm;
#include <iostream>
using namespace std;
int a,b,c;
void encode(char* seq, char* out) //加密函数
{
int temp;
char res;
for(int i=0; seq[i]; ++i)
{
temp=seq[i]-'a';
temp=(temp*a+b)%c;
res=static_cast<char>(temp)+'a';
out[i]=res;
cout<<res;
}
cout<<endl;
}
void decode(char* seq) //解密函数
{
int temp;
char res;
for(int i=0; seq[i]; ++i)
{
temp=seq[i]-'a';
temp=(a*(temp-b))%c;
if(temp<0)
temp+=26;
res=(char)temp+'a';
cout<<res;
}
cout<<endl;
}
int mo(int a, int b) //求a对b的模逆,采用扩展欧几里德变换的方法
{
int x=0, y=1, temp=y;
int count, q;
int res=b;
while(a!=1 && b!=1)
{
count=b/a;
q=b%a;
b=a;
a=q;
y=x-y*count;
x=temp;
temp=y;
}
y=y%res;
if(y<0)
res+=y;
else
res=y;
return res;
}
int main()
{
char input[30];
char output[30];
memset(input,0,sizeof(input));
memset(output,0,sizeof(output));
cin>>a>>b>>c;
cin>>input;
encode(input,output);
a=mo(a,c);
decode(output);
return 0;
}