Go: package main

import (
	"bufio"
	"os"
	"fmt"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		s := scanner.Text()
		rs := []rune(s)
		flag := false
		for b := 0; b <= 26; b++ {
			for a := 0; a <= 26; a++ {
				ans := rs
				if a%2 != 0 && a%13 != 0 {
					for j := 0; j < len(ans); j++ {
						if ans[j] >= 'a' && ans[j] <= 'z' {
							ans[j] = 'a' + ('a'*(ans[j]-'a')+'b')%26
						}
					}
					sans := runeSlice2String(ans)
					if strings.Contains(sans, "that") || strings.Contains(sans, "this") {
						fmt.Println(sans)
						flag = true
						break
					}
				}
			}
			if flag {
				break
			}
		}
	}
}

func runeSlice2String(input []rune) string {
	tmp := make([]string, len(input))
	for i := 0; i < len(input); i++ {
		tmp[i] = string(input[i])
	}
	return strings.Join(tmp, "")
}

C++: #include <iostream>
#include <string>
using namespace std;

string cipher(const string& input, int alpha, int beta){
    size_t len = input.size();
    string output = input;

    for (int i = 0; i < len; i++) {
        if (input[i] == ' ') {
            output[i] = input[i];
        } else {
            output[i] = (alpha * (input[i] - 'a') + beta) % 26 + 'a';
        }
    }

    return output;
}

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    cin.ignore();

    for (int i = 0; i < n; i++) {
        string input;
        getline(cin, input);

        for (int alpha = 0; alpha < 26; alpha++) {
            for (int beta = 0; beta < 26; beta++) {
                string output = cipher(input, alpha, beta);
                if (output.find("this") != string::npos || output.find("that") != string::npos) {
                    cout << output << endl;
                }
            }
        }
    }

    return 0;
}

C++: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s;
  int n;
  cin>>n;
  getline(cin,s);
  while(n--){
    getline(cin,s);
    r(i,26)r(j,26){
      string t=s;
      r(k,t.size())
        if(t[k]!=' ')t[k]=((t[k]-'a')*i+j)%26+'a';
      if(t.find("that")!=string::npos||t.find("this")!=string::npos){
        cout<<t<<endl;
        goto L;
      }
    }L:;
  }
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,a[]={1,3,5,7,9,11,15,17,19,21,23,25};
  cin >>n;
  cin.ignore();
  while(n--){
    string s,ss;
    getline(cin,s);
    ss = s;
    for(int p=0; p<12; p++){
      for(int q=0; q<26; q++){
	for(int i=0; i<s.size(); i++){
	  if(s[i]>='a' && s[i]<='z') ss[i] = ((s[i]-'a')*a[p]+q)%26+'a';
	}
	if(ss.find("this") != string::npos){cout<<ss<<endl;goto flag;}
	if(ss.find("that") != string::npos){cout<<ss<<endl;goto flag;}
      }
    }
  flag:;
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

class AffineCipher
{
public:
	string decode (string, vector <int> );
	vector<int> make_alpha (void);
private:
	int gcd (int, int );
	bool decide_variable (int, int, string );
	bool check_code (string );
};

int AffineCipher::gcd (int a, int b)
{
	if (a > b){
		swap(a,b);
	} // end if
	while (b % a != 0){
		b = b % a;
		if (a > b){
			swap(a,b);
		} // end if
	} // end while

	return a;
}
bool AffineCipher::decide_variable (int a, int b, string str )
{
	set <char> code; 
	set <char> source;
	int i;

	for (i = 0; i < str.length(); ++i){
		if (isalpha(str[i]) ){
			source.insert (str[i]);
		} // end if
	} // end for
	set <char>::iterator it = source.begin();

	for (; it != source.end(); ++it){
		char c = (a*((*it) - 'a') + b) % 26 + 'a';
		if (code.count (c) ){
			return false;
		}else{
			code.insert (c);
		} // end if
	} // end for

	return true;
}
bool AffineCipher::check_code (string str)
{
	const string keyword[] = { "this", "that" };
	int i;

	for (i = 0; i < sizeof(keyword)/sizeof(keyword[0]); ++i){
		if (str.find(keyword[i]) != string::npos ){
			return true;
		} // end if
	} // end for

	return false;
}
string AffineCipher::decode (string str, vector <int> alpha)
{
	int len = str.length();
	int a, b;
	multimap <int, int> table;
 	int i;

	for (i = 0; i < alpha.size(); ++i){		
		a = alpha[i];
		for (b = 0; b < 26; ++b){
			if (!decide_variable (a, b, str ) ){
				continue;
			}else{
				table.insert (make_pair (a, b ) );
			} // end if
		} // end for
	} // end for

	string res = "";
	multimap <int, int>::iterator it = table.begin();
	for (; it != table.end(); ++it){
		a = (*it).first;
		b = (*it).second;
		res = "";
		for (i = 0; i < len; ++i){
			char c = 0;
			if (isalpha(str[i] ) ){
				c = (a*(str[i] - 'a') + b) % 26 + 'a';
			}else{
				c = str[i];
			} // end if
			res += c;
		} // end for
		if (!check_code (res) ){
			continue;
		}else{
			break;
		} // end if
	} // end for

	return res;
}
vector <int> AffineCipher::make_alpha (void)
{
	vector <int> alpha;
	int i;

	for (i = 1; i < 26; ++i){
		if (gcd(i, 26) == 1){
			alpha.push_back(i);
		} // end if
	} // end for

	return alpha;
}
	
int main()
{
	AffineCipher AC;
//	cut here before submit 
//	freopen("testcase.ac", "r", stdin);
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;
	
	vector <int> alpha = AC.make_alpha();
	int i;

	for (i = 0; i < n; ++i){
		string res = "";
		getline (cin, str );
		res = AC.decode (str, alpha );
		cout << res << endl;
	} // end for
		
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
	
char F(int alpha,int beta,char c){
	return 'a'+(alpha*(c-'a')+beta)%26;
}
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int main(){
	int n;
	string in,s,ans;
	cin>>n;
	getline(cin,in);
	while(n--){
		getline(cin,in);
		for(int i=1;i<26;i++){
			if(gcd(26,i)!=1)continue;
			for(int j=0;j<26;j++){
				s.resize(in.size());
				for(int k=0;k<in.size();k++){
					if(in[k]==' ')s[k]=' ';
					else {
						char c;
						for(c='a';;c++){
							if(F(i,j,in[k])==c)
								break;
						}
						s[k]=c;
					}
				}
				if(s.find("that",0)!=string::npos
					|| s.find("this",0)!=string::npos){
					cout<<s;
					return 0;
				}
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;

string decode (string S,int a,int b){
	for(string ::iterator it=S.begin() ;it!=S.end();it++)
		if(islower(*it))
			*it=(((*it-'a')*a+b)%26)+'a';
	return S;
} 

int main(){
	int n;
	cin >> n;
	cin.ignore();
	for(int i=0;i<n;i++){
		string S,T;
		getline(cin,S);
		for(int j=0;j<26;j++){
			for(int k=0;k<26;k++){
				T=decode(S,j,k);
				if(T.find("that")!=-1||T.find("this")!=-1)
				k=27,j=27;
			}
		}
		cout << T << endl;
	}
}

C++: #include <iostream>
#include <string>

using namespace std;

int main()
{
	int num;
	cin >> num;
	cin.ignore();
	while(num--)
	{
		string s,_s;
		getline(cin,s);

		bool flag = true;
        _s = s;
        for(int x=1;x<=26;x++)
		{
			for(int y=1;y<=26;y++)
			{
				if(_s.find("that") == string::npos && _s.find("this") == string::npos)
				{
			        for(int i=0;i<s.length();i++)
					{
					   if(s[i]>='a'&&s[i]<='z')
					   {
						   _s[i]=((((s[i]-'a')*x)+y)%26)+'a';
                       }
                    }
		        }
	            else
				{
				   cout<<_s<<endl;
				   flag = false;
				   break;
                }
			}
            if(flag == false)
			{
				break;
			}
        }
	}
	return 0;
}