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 <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <set>
#include <map>

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" };

	for (int 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;
	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<cstdio>

using namespace std;

int gcd(int x,int y){
  if(y == 0)return x;
  return gcd(y,x%y);
}

int lcm(int x,int y){
  return (x*y)/gcd(x,y);
}

string affine(string s,int a,int b){
  string news;
  for(int i=0;i<s.length();i++){
    if(!('a'<= s[i] && s[i]<='z') ){
      news+=s[i];
      continue;
    }
    int y = s[i]-'a';
    news+= (char)((a*y+b)%26+'a');
  }
  
  return news;
}


int main(){

  int N;
  string s;
  cin >> N;
  cin.ignore();
  while(N-- > 0){
    getline(cin,s,'\n');
   
    bool fin = false;
    for(int a=0;a<=1000;a++){
      if(gcd(a,26) == 1){
	for(int b=0;b<=1000;b++){
	  string Ns = affine(s,a,b);	  
	  if(Ns.find("that") != string::npos || Ns.find("This") != string::npos){
	    cout << Ns << endl;
	    fin = true;
	    break;
	  }
	}

	}
	if(fin)break;
    }
    if(!fin)cout << s << endl;


  }
  return 0;
}

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

using namespace std;

string decode(string src, int a, int b) {
    string dst(src);
    int table[26];
    for (int i = 0; i < 26; i++) {
        int c = (a * i + b) % 26;
        table[c] = i;
    }
    for (int i = 0; i < src.size(); i++) {
        if (src[i] != ' ') {
            dst[i] = (char)('a' + table[(int)(src[i] - 'a')]);
        }
    }
    return dst;
}

int gcd(int n, int m) {
    if (n > m) return gcd(m, n);
    if (n == 0) return m;
    return gcd(m % n, n);
}

int main(void) {
    int n;
    cin >> n;
    cin.ignore();
    for (; n--; ) {
        string src;
        getline(cin, src);
        for (int a = 1; ; a++) {
            bool break_flag = false;
            if (gcd(a, 26) != 1) continue;
            for (int b = 0; b < 26; b++) {
                string dst = decode(src, a, b);
                if ((int)dst.find("that") != -1 || (int)dst.find("this") != -1) {
                    cout << dst << endl;
                    break_flag = true;
                    break;
                }
            }
            if (break_flag) break;
        }
    }
    return 0;
}

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

int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	}else{
		x = 1; y = 0;
	}
	return d;
}

int mod_inverse(int a, int m){
	int x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

int main(){
	int n;
	std::cin >> n;
	std::cin.ignore();
	for(;n--;){
		std::string s;
		std::getline(std::cin, s);
		for(int a=1;a<26;a++){
			if(26 % a == 0 && a != 1)continue; //素ではない
			int b = 0;
			for(;b<26;b++){
				std::string new_s = s;
				int inverse_a = mod_inverse(a, 26);
				std::transform(new_s.begin(), new_s.end(), new_s.begin(),
											 [inverse_a, b](char c){
												 if(c < 'a' || c > 'z')return c;
												 int x = c - 'a';
												 int new_x = inverse_a * (x>b?x-b:x-b+26) % 26;
												 return static_cast<char>(new_x + 'a');
											 });
				if(new_s.find("this") != std::string::npos ||
					 new_s.find("that") != std::string::npos){
					std::cout << new_s << std::endl;
					break;
				}
			}
			if(b < 26){break;}
		}
	}
}