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

int main(){
	int n;
	string s;
	cin>>n;
	getline(cin,s);
	while(n--){
		getline(cin,s);
		string ss=s;
		for(int i=0;i<99;i++){
				for(int j=0;j<26;j++){
					for(int k=0;k<s.size();k++)
						if(s[k]!=' ')ss[k]=((i*s[k]+j)%26)+'a';
					if(ss.find("that")+1||ss.find("this")+1)goto z;
				}
		}
		z:;
		cout<<ss<<endl;
	}
}

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 = 0; i < 500; i++){
      for(int j = 0; j < 500; 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<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>

using namespace std;
// F(y) = (a*y+b) mod 26
int main(){
	int n;
	scanf("%d",&n);
	bool f = false;
	while( n-- ){
		char hoge;
		hoge = getchar();
		string str;
		vector < string > vs;
		getline(cin,str);
		if(f){
			string tmp;
			tmp = hoge;
			tmp += str;
			swap(tmp,str); 
		}
		f = true;
		str+=" ";
		for(int i = 0; i < str.size()-5; i++){
			if(str[i] != ' ' && str[i+1] != ' ' && str[i+2] != ' ' && str[i+3] != ' ' && str[i+4] == ' '){
				string tmp = "";
				tmp += str[i];tmp+=str[i+1];tmp+=str[i+2];tmp+=str[i+3];
				vs.push_back(tmp);
			}
		}
		
		/*for(int i = 0; i < vs.size(); i++){
			cout << vs[i] << endl;
		}*/
		
		int a;
		int b;
		int index = 10000;
		int A = 100;
		int B = 100;
		int This[4];
		int That[4];
		for(int i = 1; i < A; i++ ){
			if(__gcd(i,26) != 1)continue;
			for(int j = 1; j < B; j++){
				if(__gcd(i,j) != 1)continue;
				This[0] = (i*('t'-'a')+j);
				This[1] = (i*('h'-'a')+j);
				This[2] = (i*('i'-'a')+j);
				This[3] = (i*('s'-'a')+j);
				
				That[0] = (i*('t'-'a')+j);
				That[1] = (i*('h'-'a')+j);
				That[2] = (i*('a'-'a')+j);
				That[3] = (i*('t'-'a')+j);
				
				for(int k = 0; k < vs.size(); k++){
					string x = "";
					string y = "";
					for(int q = 0; q < 4; q++)x+=(This[q]%26+'a');
					for(int q = 0; q < 4; q++)y+=(That[q]%26+'a');
					if(x == vs[k]){
						index = k;
						a = i;
						b = j;
						goto L;
					}
					if(y == vs[k]){
						a = i;
						b = j;
						index = k;
						goto L;
					}
				}
			}
		}
		L:;
		//printf("a = %d b = %d index = %d\n",a,b,index);
		string ans = "";
		for(int i = 0; i < str.size()-1; i++){
			int x = 0;
			if(str[i] == ' '){ans += " ";continue;}
			while((str[i]-'a'-b+x)%(a)!= 0)x+=26;
			ans += (str[i]-'a'-b+x)/a%26+'a';
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>

int gcd(int a,int b){
	return b ? gcd(b,a%b) : a;
}

int change(char str[257],int a,int b){
	int i;
	for(i = 0;str[i] != '\0';i++){
		str[i] = str[i] == ' ' ? ' ' : (a*(str[i]-'a')+b)%26+'a';
	}
	for(i = 0;str[i+3] != '\0';i++){
		if(!strncmp(str+i,"that",4) || !strncmp(str+i,"this",4)){
			return 1;
		}
	}
	
	return 0;
}

int main(void) {
	int i,n,a,b;
	char str[257],str2[257];
	
	scanf("%d",&n);
	gets(str);
	for(i = 0;i < n;i++){
		gets(str);
		for(a = 1;a < 26;a++){
			for(b = 1;b < 26;b++){
				if(gcd(a,b) != 1) continue;
				strcpy(str2,str);
				if(change(str2,a,b)){
					goto end;
				}
			}
		}
end:
		printf("%s\n",str2);
	}
	
	return 0;
}

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

bool check( string S )
{
    istringstream is( S );
    string word;
    while ( is >> word ) if ( word == "this" || word == "that" ) return true;
    return false;
}

string decode( string S )
{
    int T[S.size()];
    int F[S.size()];
    for ( int i = 0; i < (int)S.size(); i++ ) T[i] = (int)( S[i] - 'a' );

    for ( int i = 1; i < 500; i++ ) {
        if ( 26 % i == 0 ) continue;
        for ( int j = 0; j < 500; j++ ) {
            for ( int k = 0; k < (int)S.size(); k++ ) {
                F[k] = ( i * T[k] + j ) % 26;
            }
            string FS( S.size(), 'a' );
            for ( int k = 0; k < (int)S.size(); k++ ) {
                if ( S[k] == ' ' ) FS[k] = ' ';
                else FS[k] += F[k];
            }
            if ( check( FS ) ) return FS;
        }
    }
    return S;
}

int main( void )
{
    int n;
    cin >> n;
    cin.ignore();
    for ( int i = 0; i < n; i++ ) {
        string line;
        getline( cin, line );
        cout << decode( line ) << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		char str[260];
		char e[260];
		scanf("\n");
		gets(str);
		int leng=strlen(str);
			for(int i=1;i<26;i++){
				if(i%2!=0 && i%13!=0){
					for(int j=0;j<26;j++){
						string r;
						for(int y=0;y<leng;y++){
							if(str[y]-'a'>=0 && str[y]-'a'<26){
								int o=str[y]-'a';
								o=(o*i+j)%26;
								r.push_back(o+'a');
							}else{
								r.push_back(str[y]);
							}
						}
						int p=r.size();
						for(int i=0;i<p-3;i++){
							if(r[i]=='t' && r[i+1]=='h' && ((r[i+2]=='a' && r[i+3]=='t') || (r[i+2]=='i' && r[i+3]=='s'))){
								cout << r << endl;
								goto ri;
							}
					}
				}
			}
			}
ri:;
}
}