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<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
char c[257];
char d[257];
bool use[26];
int main(){
	int a;
	scanf("%d ",&a);
	while(a--){
		cin.getline(c,257);
		int t=strlen(c);
		for(int i=1;i<26;i++){
			for(int j=1;j<26;j++){
				bool ok=false;
				for(int k=0;k<26;k++)use[k]=false;
				for(int k=0;k<26;k++){
					if(use[(i*k+j)%26])goto dame;
					else use[(i*k+j)%26]=true;
				}
				for(int k=0;k<t;k++){
					if(c[k]<='z'&&c[k]>='a'){
						d[k]=(i*(c[k]-'a')+j)%26+'a';
					}else{
						d[k]=c[k];
					}
				}
				for(int k=0;k<t-3;k++){
					if(d[k]=='t'&&d[k+1]=='h'){
						if(d[k+2]=='a'&&d[k+3]=='t')ok=true;
						if(d[k+2]=='i'&&d[k+3]=='s')ok=true;
					}
				}
				if(ok){
					printf("%s\n",d);
					goto owari;
				}
				dame:;
			}
		}
		owari:;
	}
}

C++: #include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<map>
#include<cctype>
#include<cstdlib>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
const int N = 26;

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

map<char, char> makeMap(int a, int b){
    map<char, char> ret;
    REP(i, N){
        char bef = 'a' + i;
        char aft = 'a' + ((a * i + b) % N);
        ret[bef] = aft;
    }
    return ret;
}

bool isAns(string str){
    vector<string> v;
    stringstream ss(str);
    string tmp;
    while(getline(ss, tmp, ' ')) v.push_back(tmp);
    REP(i, v.size()) if(v[i] == "that" || v[i] == "this") return true;
    return false;
}

string findAns(string str){
    FOR(a, 1, N){
        if(gcd(N, a) != 1) continue;
        FOR(b, 1, N){
            map<char, char> m = makeMap(a, b);
            string tmp = str;
            REP(i, tmp.length()) if(isalpha(tmp[i])) tmp[i] = m[tmp[i]];
            if(isAns(tmp)) return tmp;
        }
    }
    return "error";
}


int main(){
    int n; cin >>n;
    string str;
    getline(cin, str);
    REP(z, n){
        getline(cin, str);
        cout <<findAns(str) <<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
using namespace std;
int inf = 1000000000;

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

int main(){

  int n;
  cin >> n;
  cin.ignore();
  for(int l=0; l<n; l++){
    string s;
    getline(cin, s);

    for(int i=1; i<50; i++){
      if( i % 2 == 0 || i % 13 == 0 ) continue;
      for(int j=1; j<50; j++){
        string t = "";
        for(int k=0; k<s.size(); k++){
          if( 'a' <= s[k] && s[k] <= 'z' ) t += affine(s[k], i, j);
          else t += s[k];
        }
        for(int k=0; k<t.size()-4; k++){
          if( (t[k] == 't' && t[k+1] == 'h' && t[k+2] == 'a' && t[k+3] == 't') || (t[k] == 't' && t[k+1] == 'h' && t[k+2] == 'i' && t[k+3] == 's') ) cout << t << endl;
        }
      }
    }

  }


  return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define rep_to(a,i,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define rep_r(i,n) for(i=n-1;i>=0;i--)
#define debug_i(x) printf("x:%d\n",x)
#define debug_s(str) printf("str:%s\n",str)
#define debug_c(c) printf("c:%c\n",c) 

int main()
{
	int i,j,k,l,z;
	int n=0;
	char str[257]={};
	char str1[257][257]={};
	char str2[257][257]={};
	char *p;
	int ans,count=1;
	int flag=0;
	int len=0;
	scanf("%d\n",&n);

	rep(z,n)
	{
		fgets(str,sizeof(str),stdin);
		str[strlen(str)-1]='\0';
		i=0;
		j=0;
		k=0;
		rep(i,strlen(str))
		{
			if(str[i]==' ')
			{
				j++;
				k=0;
				i++;
				count++;
			}
			str1[j][k]=str[i];
			k++;
		}
		rep(k,count)
		{
			if(strstr(str1[k],"that")!=NULL)flag=2;
			else if(strstr(str1[k],"this")!=NULL)flag=2;
		}
		if(flag!=2)
		{
			while(1)
			{
				rep_to(1,j,1000)
				{
					rep(k,count)
					{
						if(strstr(str2[k],"that")!=NULL)flag=1;
						else if(strstr(str2[k],"this")!=NULL)flag=1;
					}
					if(flag==1)break;
					rep(k,count)
					{
						rep(l,strlen(str1[k]))
						{
							str2[k][l]=(i*(str1[k][l]-97)+j)%26+97;
						}
					}
				}
				if(flag==1)break;
				i++;
			}
			rep(i,count)
			{
				rep(j,strlen(str2[i]))
				{
					if(len>=strlen(str))break;
					else 
					{
						printf("%c",str2[i][j]);
						len++;
					}
				}
				if(len>=strlen(str))break;
				else printf(" ");
				len++;
			}
			printf("\n");
		}
		else
		{
			rep(i,count)
			{
				rep(j,strlen(str1[i]))
				{
					if(len>=strlen(str))break;
					else 
					{
						printf("%c",str1[i][j]);
						len++;
					}
				}
				if(len>=strlen(str))break;
				else printf(" ");
				len++;
			}
			printf("\n");
		}
		
		flag=0;
		rep(i,strlen(str))str[i]='\0';
		rep(i,count)rep(j,strlen(str2[i]))str2[i][j]='\0';
		rep(i,count)rep(j,strlen(str1[i]))str1[i][j]='\0';
		count=1;
		i=0;
		len=0;
	}
	return 0;
}

C++: #include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef vector <int> vi;
typedef map <char,char> mapcc;
#define REP(i,n) for (int i=0; i<n; i++)
string A2Z="abcdefghijklmnopqrstuvwxyz";
struct affine_key{
	int a;
	int b;
};

string decode(mapcc &mp, string &msg){
	string s="";
	int i=0;
	while (msg[i]){
		char c = msg[i];
		if (islower(c)) c = mp[c];
		s += c;
		i++;
	}
	return s;
}

string affine(string &msg, int a=0, int b=0){
	
	mapcc mp;
	REP(i,26){
		int i1 = i*a+b;
		while (i1<0) i1 += 26;
		mp[A2Z[i]] = A2Z[i1 % 26];
	}
	return decode(mp, msg);
}

string rot(string &msg, int a){
	if (a==0) return msg;
	mapcc mp;
	while (a<0) a += 26;
	REP(i,26)
		mp[A2Z[i]] = A2Z[(i+a) % 26];
	return decode(mp, msg);
}

vi find(string &msg){
	char c0='t';
	vi key(2);
	int a,b;
	for (int i=1; i<26; i+=2){
		a = i;
		string x = affine(msg, a, 0);
		b = c0-x[0];
		if (b<0) b += 26;
		x = rot(x, b);
		if (x=="this" || x=="that"){
			key[0] = a;
			key[1] = b;
			return key;
		}
	}
	key[0] = -1;
	return key;
}

int main(void){
	int n;
	cin>>n;
	cin.ignore();
	REP(i,n){
		vi key;
		string msg, word;
		getline(cin, msg);
		istringstream is(msg);
		while(is>>word)
			if (word.size()==4){
				key = find(word);
				if (key[0] != -1) break;
			}
		cout<<affine(msg, key[0], key[1])<<endl;
	}
}

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

using namespace std;

string Affine(string S)
{
	vector<int> F(26);

	for (int i = 0; i < 26; i++) // alpha
	{
		for (int j = 0; j < 26; j++) // beta
		{
			for (int k = 0; k < 26; k++) // gamma
			{
				F[k] = (i * k + j) % 26;
			}
			
			string T = S;

			for (int k = 0; k < S.size(); k++)
			{
				if (islower(S[k]))
				{
					T[k] = F[S[k] - 97] + 97;
				}
				else
				{
					T[k] = S[k];
				}
			}

			if (T.find("this") != string::npos || T.find("that") != string::npos)
			{
				return T;
			}
		}
	}

	return "";
}

int main()
{
	int n; string S;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		S = "";

		while (S == "")
		{
			getline(cin, S);
		}

		cout << Affine(S) << endl;
	}
	
	return 0;
}