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>
#include <sstream>
#include <vector>

using namespace std;

string encrypt(string str, int alpha, int beta){
  int size = str.size();
  string ret = "";

  for(int i=0;i<size;i++){
	if('a' <= str[i] && str[i] <= 'z'){
	  ret += (alpha * (str[i] - 'a') + beta) % 26 + 'a';
	}
  }

  //cout << str << " is encrypted to: "<< ret << endl;
  return ret;
}

int main(void){
  string thiss("this");
  string that("that");
  int n;

  cin >> n;
  cin.ignore(); //CR+LF
  for(int i=0;i<n;i++){
	vector<string> strv;
	string str, tmp;
	getline(cin, str);
	int numwords;
	istringstream iss(str);
	int alpha, beta;
	bool decided = false;

	decided = false;
	while(iss >> tmp){
	  strv.push_back(tmp);
	}
	numwords = strv.size();

	for(int j=0;j<numwords;j++){
	  /* test */
	  //cout << "checking: " << strv[j] << endl;
	  /* */
	  if(strv[j].size() == 4){
		if(strv[j][0] == strv[j][3]){// strv[j] is a candidate of that
		  //cout << "candidate of that" << endl;
		  beta = strv[j][2] - 'a';
		  //cout << "beta is " << beta << endl;
		  //calc alpha
		  int k=0;
		  while(strv[j][0] - 'a' +k*26 < beta || (k*26 + strv[j][0] - 'a' - beta) % 19 != 0){ // 19 == t
			k++;
		  }
		  alpha = (k*26+(strv[j][0] - 'a' - beta)) / 19;
		  //cout << "alpha is " << alpha << endl;
		  string encrypted = "";
		  encrypted = encrypt("that", alpha, beta);
		  if(strv[j] == encrypted){
			decided = true;
		  }
		}else{// strv[j] is a candidate of this
		  //cout << "candidate of this" << endl;
		  tmp = strv[j];
		  if(tmp[0] < tmp[3]) tmp[0] += 26;
		  alpha = tmp[0] - tmp[3];
		  //cout << "alpha is " << alpha << endl;
		  if(tmp[3] - 'a' >= alpha * 18 % 26){
			beta = tmp[3] - 'a' - alpha * 18 % 26;
		  }else{
			beta = tmp[3] - 'a' + 26 - alpha * 18 % 26;
		  }
		  //cout << "beta is " << beta << endl;
		  string encrypted = encrypt("this", alpha, beta);
		  if(strv[j] == encrypted){
			decided = true;
		  }
		}
	  }
	  if(decided) break;
	}

	//decrypt
	for(int j=0;j<str.size();j++){
	  int k=0;
	  if('a' <= str[j] && str[j] <= 'z'){
		while(str[j]-'a' + k*26 < beta || (k*26 + str[j] - 'a' - beta) % alpha != 0) k++;
		str[j] = ((k*26 + str[j] - 'a' - beta) / alpha) + 'a';
	  }
	}
	cout << str << endl;
  }

  return 0;
}

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

using namespace std;

int a,b;
map<char, char> M;

char Affine(char c){
  return ((a*(c-'a') + b) % 26) + 'a';
}


void make(){
  M.clear();
  for(char c = 'a'; c <= 'z'; c++)
    M[Affine(c)] = c;
}


bool check(string in){
  string now = "";
  for(int i = 0; i < in.length(); i++){
    if(in[i] == ' '){
      //   cout << "now = " << now << endl;
      if(now == "this" || now == "that") return true;
      now = "";
    }
    else now += in[i];
  }
  return false;
}

string solve(string s){
 
  for(int i = 0; i < s.length(); i++)
    if(s[i] != ' ') s[i] = M[s[i]];

  if(check(s)) return s;
  return "-1";

}

void print(){
  for(char c = 'a'; c <= 'z'; c++)
    cout << M[c] << " ";

  cout << endl;

}

int GCD(int x,int y){
  if(y==0) return x;
  return GCD(y,x%y);
}
int main(){
  
  // print();
  // return 0;
  int n;
  cin >> n;
  cin.ignore();
  while(n--){
    string s;
    bool flg = false;
    getline(cin,s);
    for(int i = 1; i < 500; i+=2){
      for(int j = 0; j < 300; j++){
	a = i;
	b = j;
	if(GCD(a,26) != 1) continue;
	
	make();
	string ans;
	
	if((ans = solve(s)) != "-1"){
	  flg = true;
	  cout << ans << endl;
	  break;
	}
      }
      if(flg) break;
    }
    
  }
  return 0;
}

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

using namespace std;

char affine(int a,int b,char c)
{
	if(c==' ')	return c;
	return 'a'+(a*(c-'a')+b)%26;
}

int main()
{
	int a[]={1,3,5,7,9,11,15,17,19,21,23,25,0};
	int n;	cin>>n;
	string ciph,ciph_copy,sp=" ";

	while(getline(cin,ciph)){
		ciph=ciph_copy=sp+ciph+sp;
		bool f=false;
		for(int i=0;!f&&a[i];i++){
			for(int b=0;!f&&b<26;b++){
				for(int j=0;j<ciph.length();j++)
					ciph[j]=affine(a[i],b,ciph[j]);

				if(ciph.find(" that ")!=string::npos
				|| ciph.find(" this ")!=string::npos){
					f=true;
					break;
				}

				ciph=ciph_copy;
			}
		}
		cout<<ciph.substr(1,ciph.length()-2)<<endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

string change(string s,int a,int b){
	string ret(s);
	rep(i,0,ret.size()){
		int y=ret[i]-'a';
		y=(a+y+b)%26;
		ret[i]='a'+y;
	}
	return ret;
}

int gcd(int a,int b){
	if(b==0) return a;
	return gcd(b,a%b);
}

int main(){
	int n;
	cin>>n;
	string str[2]={"that","this"};
	rep(i,0,n){
		string s;
		bool f=0;
		getline(cin,s);
		rep(a,0,26){
			if(gcd(a,26)==1) continue;
			rep(b,0,26){
				string t;
				t=change(s,a,b);
				rep(j,0,2){
					if(t.find(str[j])){
						o(t); f=1; break;
					}
				}
				if(f) break;
			}
			if(f) break;
		}

	}
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;


int gcd(int a, int b)
{
	if (a < b)
		return gcd(b, a);
	if (b == 0)
		return a;

	return gcd(b, a%b);
}

int main()
{
	int n;
	scanf("%d ", &n);
	for (int ww = 0; ww < n; ++ww)
	{
		char enc[1<<8+1];
		fgets(enc, sizeof(enc), stdin);
		enc[strlen(enc)-1] = '\0';

		bool isFound = false;
		for (int a = 3; ; ++a)
		{
			if (gcd(a, 26) != 1)
				continue;

			int da[26];
			for (int i = 0; i < 26; ++i)
				da[(a*i)%26] = i;
			for (int b = 0; b < 25; ++b)
			{
				int dt[26];
				for (int i = 0; i < 26; ++i)
					dt[i] = da[(i+b)%26];

				char dec[1<<8+1];
				for (int i = 0; enc[i] != '\0'; ++i)
				{
					char c;
					if (islower(enc[i]))
						c = dt[enc[i]-'a'] + 'a';
					else
						c = enc[i];
					
					dec[i] = c;
				}
				dec[strlen(enc)] = '\0';

				if (strstr(dec, "that") || strstr(dec, "this"))
				{
					puts(dec);
					isFound = true;
					break;
				}
			}
			if (isFound)
				break;
		}
	}

	return 0;
}