Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("afin1.in");
- ofstream fout("afin1.out");
- int a, b, expr[27];
- string mess;
- int modInverse(int a, int b)
- {
- int b0 = b, t, q;
- int x0 = 0, x1 = 1;
- if (b == 1) return 1;
- while (a > 1)
- {
- q = a / b;
- t = b, b = a % b, a = t;
- t = x0, x0 = x1 - q * x0, x1 = t;
- }
- if (x1 < 0) x1 += b0;
- return x1;
- }
- int main()
- {
- fin>>a>>b;
- fin>>mess;
- for(int i=0; i<26; i++)
- expr[i]=(a*i+b)%26;
- int ok=0;
- for(int i=0; i<25 && !ok; ++i)
- for(int j=i+1; j<26 && !ok; ++j)
- if(expr[i]==expr[j])
- ok=1;
- if(ok)
- {
- fout<<-1;
- return 0;
- }
- for(int i=0; mess[i]; ++i)
- fout << (char)(modInverse(a, 26) * (26 + mess[i] - 'a' - b) % 26 + 'a');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement