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++: //Affine Cipher
#include<bits/stdc++.h>
using namespace std;

int a[11]={3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25};
vector<string> v;

void print(vector<string> p){
  for(int i=0; i<p.size(); i++){
    cout<<p[i];
    if(i==p.size()-1)cout<<endl;
    else cout<<' ';
  }
}

//n:aの配列番号
bool judge(int n, int b){
  vector<string> tmp;
  tmp=v;
  for(int i=0; i<tmp.size(); i++){
    for(int j=0; j<tmp[i].length(); j++){
      tmp[i][j]=((a[n]*((tmp[i][j]-'a'-b)>=0 ? tmp[i][j]-'a'-b : tmp[i][j]-'a'-b+26))%26)+'a';
    }
  }
  for(int i=0; i<tmp.size(); i++){
    if(tmp[i]=="that" || tmp[i]=="this"){
      print(tmp);
      return true;
    }
  }
  return false;
}

void solve(){
  for(int i=0; i<11; i++){
    for(int j=0; j<26; j++){
      if(judge(i, j))return;
    }
  }
}

int main(){
  int n;
  scanf("%d\n", &n);
  for(int i=0; i<n; i++){
    string s, t;
    v.clear();
    getline(cin, s);
    stringstream ss(s);
    while(getline(ss, t, ' ')) v.push_back(t);
    solve();
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;char st;
    cin>>n;
    string str;
    for(int i=0;i<=n;i++){
        while(getline(cin,str)){
        bool kawa=0;
        for(int j=1;j<50&&!kawa;j++){
            for(int k=1;k<50&&!kawa;k++){
                string strin=str;
                for(int l=0;strin[l]!='\0';l++)
                	if(strin[l]-'a'>=0&&strin[l]-'z'<=0)
                		strin[l]=(j*(strin[l]-'a')+k)%26+'a';
                for(int l=0;strin[l]!='\0';l++){
                    if(strin[l]=='t'&&strin[l+1]=='h'&&
                    		(strin[l+2]=='a'&&strin[l+3]=='t'||strin[l+2]=='i'&&strin[l+3]=='s')){
                    	cout<<strin<<endl;
                    	kawa=1;
                    	break;
                    }
                }
            }
        }
        }
    }
}

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 = 500;
		int B = 500;
		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<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;
  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<=99;a++){
      // if(gcd(a,26) == 1){
	for(int b=0;b<=99;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;
    }



  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<sstream>
int calc_alpha(const std::string&w, const char*str)
{
	auto distance = [](char from, char to)
	{
		int result = static_cast<int>(to - from);
		return result + (result < 0 ? 26 : 0);
	};
	int dis1[3], ratio[3];
	for (int j = 0; j < 3; j++)
	{
		dis1[j] = distance(w[j], w[j + 1]);
		int dis2 = distance(str[j], str[j + 1]);
		while (true)
		{
			if (dis1[j] % dis2 == 0)
			{
				ratio[j] = dis1[j] / dis2;
				break;
			}
			dis1[j] += 26;
		}
	}
	return ratio[0] == ratio[1] && ratio[1] == ratio[2] ? ratio[0] : -1;
}
int main()
{
	int n;
	std::cin >> n;
	std::cin.ignore();
	for (int i = 0; i < n; i++)
	{
		std::string str;
		std::getline(std::cin, str);
		std::stringstream ss(str);
		int alpha, beta;
		for (std::string w; ss >> w;)
		{
			if (w.length() == 4)
			{
				alpha = w[0] == w[3] ? calc_alpha(w, "that") : calc_alpha(w, "this");
				if (alpha != -1)
				{
					beta = static_cast<int>(w[0] - 'a' - ('t' - 'a') * alpha % 26);
					break;
				}
			}
		}
		char deciphered[26];
		for (char j = 'a'; j <= 'z'; j++)
		{
			char ciphered = ((j - 'a') * alpha + beta) % 26 + 'a';
			deciphered[ciphered - 'a'] = j;
		}
		for (auto j : str)
		{
			std::cout << (j == ' ' ? ' ' : deciphered[j - 'a']);
		}
		std::cout << std::endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
char c[257];
char d[257];
bool use[26];
int gcd(int a,int b){
	while(a){
		b%=a;
		int val=b;
		b=a;
		a=val;
	}
	return b;
}
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;
				if(gcd(i,j)>1)goto dame;
				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:;
	}
}