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++: //0040 Affine Cipher

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


const int N = 26;
void Transrate(string &refStr, int a, int b)
{
	for(int i = 0; i < refStr.size(); i++)
	{
		refStr[i] = (a*(refStr[i]-'a') + b)%N + 'a';
	}
}

int GCD(int a, int b)
{
	int c;
	while((c = a%b) != 0)
	{
		a = b;
		b = c;
	}
	return b;
}

int main(void)
{
	int n;
	string from, to;
	cin >> n;
	getline(cin, to);	//êsÚÌüsð

	while(n--)
	{
		getline(cin, to);
		int i, j;
		int a, b;
		from.resize(to.size());

		string t1, t2;
		for(a = 1; a < N; a++)
		{
			if(GCD(N, a) != 1)
				continue;
			for(b = 0; b < N; b++)
			{
				t1 = "this";
				t2 = "that";
				Transrate(t1, a, b);
				Transrate(t2, a, b);

				if( (to.find(t1) != string::npos) ||
					(to.find(t2) != string::npos) )
				{
					for(i = 0; i < to.size(); i++)
					{
						if(isalpha(to[i]))
						{
							for(j = 0; j < N; j++)
							{
								if(to[i] == (a*j+b)%N + 'a')
								{
									from[i] = j+'a';
									break;
								}
							}
						}
						else
							from[i] = to[i];
					}
					cout << from << endl;
					goto END;
				}
			}
		}
	END:
		;
	}
	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";

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<iostream>
using namespace std;

char encrypt(char x, int a, int b){
    return (char)(((x-'a') * a + b)%26 + 'a');
}

int main(){
    int n;
    scanf("%d\n", &n);

    string str, copy;
    for(int i = 0; i < n; i++){
        getline(cin, str);
        int a, b;
        bool found = false;
        for(a = 1; !found ; a++){
            if(a % 2 == 0 || a % 13 == 0)    continue;
            for(b = 1; b <= 26; b++){
                copy = str;
                for(int k = 0; k < str.length(); k++){
                    if(str[k] != ' ')   copy[k] = encrypt(str[k], a, b);
                }
                if(copy.find("this") != -1 || copy.find("that") != -1){
                    cout << copy << endl;
                    found = true;
                    break;
                }
            }
        }
    }

    return 0;
}

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

int main(){
	int n, len;
	char str[257] = {}, str_c[257];
	cin >> n;
	getchar();
	for (int m = 0; m < n; m++){
		int flag = false;
		gets(str);
		len = strlen(str);
		//printf("%d\n", len);
		for (int i = 0; i < 26; i++){
			/*if (i % 2 == 0 || i % 13 == 0) continue;*/
			for (int j = 0; j < 26; j++){
				for (int k = 0; k <= len; k++){
					if (isalpha(str[k])){
						str[k] -= 'a';
						str_c[k] = (str[k] * i + j) % 26 + 'a';
						str[k] += 'a';
					}
					else{
						str_c[k] = str[k];
					}
				}
				if (strstr(str_c, "this") || strstr(str_c, "that")){
					printf("%s\n", str_c);
					flag = true;
					break;
				}
			}
			if (flag) break;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	int n; 
	string in;
	getline(cin,in);
	n=atoi(in.c_str());
	while(n--)
	{
		getline(cin,in);
		int dig[26];
		string ans="";
		bool flag=false;
		for(int i = 1;;i+=2)
		{
			if(i%13==0) continue;
			for(int j = 0; j < 26; ++j)
			{
				for(int k = 0; k < 26; ++k)
				{
					dig[k]=(i*k+j)%26;
				}
				ans="";	
				for(int k = 0; k < in.size(); ++k)
				{
					if(in[k]==' ') ans+=' ';
					else 
					{
						char tmp='a'+dig[in[k]-'a'];
						ans+=tmp;
					}
				}
				//cout<<ans<<endl;
				if(ans.find("that")!=-1||ans.find("this")!=-1)
				{
					cout<<ans<<endl;
					flag=true;
				}
				if(flag) break;
			}
			if(flag) break;
		}

	}
  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;
  news.clear();
  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<=50;a++){
      if(gcd(a,26) == 1){
	for(int b=0;b<26;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>
#include<cstdio>
using namespace std;

string THIS = "this", THAT = "that";
int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
int main() {
	int a;
	string b;
	cin >> a;
	getline(cin, b);
	for (int c = 0; c < a; c++) {
		getline(cin, b);
		for (int d = 1; d < 26; d++) {
		l:;
			for (int e = 0; e < 26; e++) {
				if (gcd(d, 26) != 1)continue;
				string s;
				for (int f = 0; f < b.length(); f++) {
					if (b[f] == ' ')s += ' ';
					else {
						for (int g = b[f] - 'a';g<26*26+'a'; g += 26) {
							if ((g - e) % d == 0 && (g - e) / d >= 0 && (g - e) / d < 26) { s += ((g - e) / d + 'a'); goto r; }
						}
						goto l;
					r:;
					}
				}
				for (int i = 0; i < s.length() - 3; i++) {
					bool x = true, y = true;
					for (int p = 0; p < 4; p++) {
						if (s[i + p] != THIS[p])x = false;
						if (s[i + p] != THAT[p])y = false;
					}
					if (x | y) { cout << s << endl; break; }
				}
			}
		}
	}
}