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

int main() {
  int b,c, n, l;
  int a[12] = {1,3,5,7,9,11,15,17,19,21,23,25};
  char t[12][26];
  char buf[300];
  bool dec;
  for (int i=0; i<12; i++) {
    for (int j=0; j<26; j++) {
      t[i][(a[i]*j)%26] = j;
    }
  }

  string str, tmp;
  cin >> n;
  while (n--) {
    dec = false;
    do {
      getline(cin, str);
    } while (str == "");
    l = (int)str.size();
    for (int i=0; i<12; i++) {
      for (int j=0; j<26; j++) {
        memcpy(buf, str.c_str(), sizeof(char)*l+1);
        for (int k=0; k<l; k++) {
          if (islower(buf[k])) buf[k] = t[i][(buf[k]-'a'-j+26)%26]+'a';
        }
        tmp.assign(buf);
        if (tmp.find("that")!=string::npos || tmp.find("this")!=string::npos) {
          dec = true;
          break;
        }
      }
      if (dec) break;
    }
    cout << tmp << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool isalpha(char z){
	if(z>='a'&&z<='z')return true;
	else return false;
}
int main(){
	string s,c;
	int n;
	cin>>n;
	for(int u=0;u<n;u++){
		cin.ignore();
		getline(cin,s);
		int a=0;
		bool ok=false;
		while(true){
			int b=0;
			while(true){
				c=s;
				for(int i=0;i<s.size();i++){
					if(isalpha(c[i])){
						c[i]='a'+((c[i]-'a')*a+b)%26;
					}
				}
				for(int i=0;i<s.size()-3;i++){
					if(c[i]=='t'&&c[i+1]=='h'&&c[i+2]=='i'&&c[i+3]=='s')ok=true;
					if(c[i]=='t'&&c[i+1]=='h'&&c[i+2]=='a'&&c[i+3]=='t')ok=true;
				}
				if(ok)break;
				b++;
				if(b==26)break;
			}
			if(ok)break;
			a++;
		}
		cout<<c<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
    // まず、mod26上のAと26がお互いに素となるAの値は、
    // {1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25}
    // である。問題で変換したアフィン暗号のパラメータAは、
    // この条件を満たすため、Aはこの範囲で決定できる。
    // 次に、A*(A^) mod 26 = 1となるモジュロ逆数A^は
    // {1, 9, 21, 15, 3, 19, 7, 23, 11, 5, 17, 25}
    // となるが、集合と見た場合はAと一致する。よって、
    // 順序を気にしない全探索の場合はAのパラメータを回すだけでよい
    int n;
    const int palmA[] = {1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25};

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

        for(auto a : palmA) {
            for(int b = 0; b < 26; b++) {
                string plain;
                // 複合処理
                // 暗号化関数 F(l)=(al+b) mod 26 より
                // 復号化関数 F^(l)=a(l-b) mod 26
                for(auto v : cipher)
                    plain += (v == ' ') ? ' ' : (a*((v-'a')+b) % 26 + 'a');
                if(plain.find("this") != -1 || plain.find("that") != -1) {
                    cout << plain << endl;
                }
            }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <sstream>
#include <math.h>

using namespace std;

string check(string str);
map<char, int> create_table();
int gcd(int a, int b);

int main(){
  char ch = 'a';
  string str;
  int num;
  vector<string> answers;
  map<char,int> table = create_table();
  cin >> num;

  cin.ignore();
  for(int k=0; k<num; k++){
    getline(cin, str);

    char c;
    char list[1];
    bool flag = true;
    int beta;
    int alpha = 1;
    map<char, int>::iterator itr;
    while(flag){
      if(gcd(alpha,26) == 1){ 
        for(beta=1; beta<26; beta++){
          string result;
          for(int i=0; i<str.size(); i++){
            c = str[i];
            if(c != ' '){
              sprintf(list, "%c", ch+(alpha*table[c]+beta)%26);
              result += list[0];
            }else{
              result += ' ';
            }
          }
          if(result.find("this",0) !=string::npos || result.find("that",0) != string::npos){
            answers.push_back(result);
            flag = false;
            break;
          }
        }
      }
      alpha++;
    }
  }

  for(int j=0; j<answers.size(); j++){
    cout << answers[j] << endl;
  }
  return 0;
}


map<char, int> create_table(){
  map<char, int> table;
  char ch[1];
  char str = 'a';

  for(int i=0; i<26; i++){
    sprintf(ch, "%c", str+i); 
    table.insert(pair<char,int>(ch[0],i));
  }
  return table;
}

int gcd(int a, int b){
  int temp;
  while(b==0){
    temp = a;
    a = temp/b;
    b = temp%b;
  }
  if(a==0)a=1;
  return a;
}

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

#define rep(a, b, i) for(int i = a; i < b; i++)

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

int main() {
	int n, a, b, c;
	cin >> n;
	cin.ignore();

	string str, res = "";
	for (; n > 0; n--) {
		getline(cin, str);

		rep(1, 25, a) {
			if (a == 2 || a == 13) continue;
			rep(1, 27, b) {
				res = str;
				c = 0;
				rep(0, str.size(), c) {
					if (res[c] == ' ') continue;

					res[c] = ch(a, b, res[c]);
				}
				if (res.find("this") != -1 || res.find("that") != -1) {
					cout << res << endl;
					a = 114514;
					b = 114514;
				}
			}
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>

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

int main(){
	int n;
	char t = 'a';
	char s[257];
	char that[] = "that";
	char thi[] = "this";
	char athat[5], athis[5], r[26], rt[26];
	scanf("%d\n", &n);
	for(int i = 0; i < n; i++){
		int d = 0;
		int a = 0;
		scanf("%c", &t);
		while(t - 10){
			s[d] = t;
			d++;
			scanf("%c", &t);
		}
		s[d] = 0;
		while(a + 1){
			for(int b = 0; b < 26; b++){
				for(int c = 0; c < 4; c++){
					athat[c] = affine(that[c], a, b);
					athis[c] = affine(thi[c], a, b);
				}
				athat[4] = 0;
				athis[4] = 0;
				if(strstr(s, athat) || strstr(s, athis)){
					for(int j = 0; j < 26; j++){
						rt[j] = affine(j + 'a', a, b) - 'a';
						r[rt[j]] = j;
					}
					d = 0;
					while(s[d]){
						if(s[d] != ' '){
							printf("%c", r[s[d] - 'a'] + 'a');
						}else{
							printf(" ");
						}
						d++;
					}
					printf("\n");
					a = -2;
				}
			}
			a++;
		}

	}	
}