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, "")
}

Python: n=int(input())
for i in range(n):
    import math
    s=input()
    s_l=list(map(str,s.split()))
    s_ci=[]
    for i in s_l:
        if len(i)==4:
            k_l=[]
            for j in i:
                k=ord(j)-97
                k_l.append(k)
            s_ci.append(k_l)
    a_list=[]
    for i in range(1,1000):
        if math.gcd(i,26)==1:a_list.append(i)
    for a in a_list:
        for b in range(26):
            for k in s_ci:
                word=""
                for l in k:
                    word+=chr(((l*a-b)%26)+97)
                if word=="that" or word=="this":break
            if word=="that" or word=="this":break
        if word=="that" or word=="this":break
    s_l=[]
    for i in s:
        if i==" ":
            s_l.append(-1)
        else:
            k=ord(i)-97
            s_l.append(k)
    ans=""
    for i in s_l:
        if i==-1:ans+=" "
        else:
            ans+=chr(((i*a-b)%26)+97)
    print(ans)

Python: string = 'abcdefghijklmnopqrstuvwxyz'
table = []
for i in string:
    table.append(i)

def encode(string,a,b):
    data = list(string)
    s = []
    flag = 0
    for c in data:
        try:
            i = table.index(c)
            tmp = (a*i+b)%26
            s[-1:] += table[tmp]
        except:
            s.append(' ')
    s = ''.join(s)
    return s

n = int(input())
for i in range(n):
    code = str(input())
    for a in range(1,26):
        for b in range(1,26):
            s = encode(code,a,b)
            if 'that' in s:
                print(s)
                break
            elif 'this' in s:
                print(s)
                break

Python: z='abcdefghijklmnopqrstuvwxyz'
e=lambda x,i,j:z[(z.index(x)*i+j)%26]
def f():
 for i in range(1,26,2):
  for j in range(26):
   if''.join(e(c,i,j)for c in'that')in s or''.join(e(c,i,j)for c in'this')in s:return(i,j)
for _ in[0]*int(input()):
 s=input()
 print(s.translate(str.maketrans(''.join(e(c,*f())for c in z),z)))

Python: # AOJ 0040: Affine Cipher
# Python3 2018.6.27 bal4u

M = 26
A = ord('a')

re_prime = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25]

def F(ch):
	global a, b
	x = ord(ch)-A
	return chr((a*x + b) % M + A)

dic = {}
for a in re_prime:
	for b in range(M):
		dic[F('t')+F('h')+F('i')+F('s')] = (a, b)
		dic[F('t')+F('h')+F('a')+F('t')] = (a, b)

n = int(input())
for i in range(n):
	s = list(input().split())
	for x in s:
		if len(x) == 4 and x in dic:
			a,b = dic[x]
			break
	tr = {}
	for i in range(M): tr[F(chr(i+A))] = chr(i+A)
	ans = []
	for x in s: ans.append(''.join([tr[c] for c in x]))
	print(*ans)

Python: z='abcdefghijklmnopqrstuvwxyz'
e=lambda x,i,j:z[(z.index(x)*i+j)%26]
def f():
 for i in range(1,26,2):
  for j in range(26):
   if''.join(e(c,i,j)for c in'that')in s or''.join(e(c,i,j)for c in'this')in s:return(i,j)
for _ in[0]*int(input()):
 s=input()
 k=f()
 print(s.translate(str.maketrans(''.join(e(c,*k)for c in z),z)))

Python: A_BASE = ord('a')
A = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25]

def brute_force(len4s, dwords):
    b = 0
    for a in A:
        while b < 26:
            for word in len4s:
                dec = [(a * r + b) % 26 for r in word]
                if dec in [[19, 7, 8, 18], [19, 7, 0, 19]]:
                    dec_words = [''.join([chr((a*r + b) % 26 + A_BASE) for r in dw]) for dw in dwords]
                    return ' '.join(dec_words)
            b += 1
        b = 0

def solve():
    n = int(input())
    for _ in range(n):
        text = input()
        words = text.split()
        dwords = [[ord(ch) - A_BASE for ch in word] for word in words]
        len4s = [dw for dw in dwords if len(dw) == 4]
        print(brute_force(len4s, dwords))

if __name__ == "__main__":
    solve()

Python: from itertools import product
n = int(input())
for _ in range(n):
    s = input()
    for alpha,beta in product([1,3,5,7,9,11,15,17,19,21,23,25],range(26)):
        g = "".join(chr((alpha*(ord(e)-ord("a"))+beta)%26+ord("a")) if not e == " " else " "  for e in s)
        if "that" in g or "this" in g: print(g); break

Python: base = ord("a")
alst = [i for i in range(1, 26, 2) if i % 13]
def restore(s):
  for a in alst:
    for b in range(26):
      new = "".join([chr((a * (ord(x) - base) + b) % 26 + base) if x != " " else " " for x in s])
      if "that" in new or "this" in new:
        return new

n = int(input())

for _ in range(n):
  print(restore(input()))

Python: z='abcdefghijklmnopqrstuvwxyz'
e=lambda x,i,j:z[(z.index(x)*i+j)%26]
def f():
 for i in range(1,26,2):
  for j in range(26):
   if sum(''.join(e(c,i,j)for c in w)in s for w in['that','this']):return(i,j)
for _ in[0]*int(input()):
 s=input()
 k=f()
 print(s.translate(str.maketrans(''.join(e(c,*k)for c in z),z)))

Python: z='abcdefghijklmnopqrstuvwxyz'
for _ in[0]*int(input()):
 e=input()
 for i in range(1,26,2):
  for j in range(26):
   a=''
   for c in e:
    a+=z[(z.index(c)*i+j)%26]if c in z else c
   if'that'in a or'this'in a:print(a);break

Python: n = int(input())
s = "abcdefghijklmnopqrstuvwxyz"
for i in range(n):
  sent = input().rstrip()
  l = [i for i in sent]
  c = 0
  for a in range(26):
    for b in range(26):
      l2 = []
      for i in range(len(l)):
        if l[i] in s:
          l2.append(s[(s.index(l[i])*a+b)%26])
        else:
          l2.append(l[i])
      sent2 = "".join(l2)
      if ("that" in sent2) or ("this" in sent2):
        print(sent2)

Python: # AOJ 0040: Affine Cipher
# Python3 2018.6.27 bal4u

M = 26
A = ord('a')
dic = {}
re_prime = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25]

def F(ch):
	global a, b
	x = ord(ch)-A
	return (a*x + b) % M
		
for a in re_prime:
	for b in range(M):
		n = ((F('t')*M + F('h'))*M + F('i'))*M + F('S')
		dic[n] = (a, b)
		n = ((F('t')*M + F('h'))*M + F('a'))*M + F('t')
		dic[n] = (a, b)

n = int(input())
for i in range(n):
	s = list(input().split())
	for x in s:
		if len(x) == 4:
			n = 0
			for c in x:	n = n*M + (ord(c)-A)
			if n in dic:
				a,b = dic[n]
				break
	tr = {}
	for i in range(M): tr[chr(A+F(chr(i+A)))] = chr(i+A)
	ans = []
	for x in s: ans.append(''.join([tr[c] for c in x]))
	print(*ans)

Python: from string import ascii_lowercase


def ex_gcd(a, b, y0=0, y1=1):
    s, r = a // b, a % b
    return ex_gcd(b, r, y1, y0 - s * y1) if r else y1


def decrypt(c, a_rev, b):
    return chr(a_rev * (ord(c) - 97 - b) % 26 + 97) if c in ascii_lowercase else c


decrypt_that = {}
decrypt_this = {}

for a in (1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25):
    for b in range(26):
        _t, _h, _a, _i, _s = map(lambda c: chr((a * c + b) % 26 + 97), (19, 7, 0, 8, 18))
        decrypt_that[''.join((_t, _h, _a, _t))] = (a, b)
        decrypt_this[''.join((_t, _h, _i, _s))] = (a, b)

n = int(input())
while n:
    line = input()
    word4 = {w for w in line.split() if len(w) == 4}
    a, b = 0, 0
    for word in word4:
        if word in decrypt_that:
            a, b = decrypt_that[word]
            break
        if word in decrypt_this:
            a, b = decrypt_this[word]
            break
    a_rev = ex_gcd(26, a)
    print(''.join(decrypt(c, a_rev, b) for c in line))

    n -= 1