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: m = [chr(ord('a')+i) for i in range(26)]
t = {}
for i in range(26):
    t[m[i]] = i


def affine(s):
    for a in range(26):
        for b in range(26):
            text = ''.join([m[a * (t[x] - b + 26) % 26]
                            if x != ' ' else ' ' for x in s])
            if 'that' in text or 'this' in text:
                return text


n = int(input())

for i in range(n):
    print(affine(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''.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)
def g(x,y,s=0,t=1):
 q,r=x//y,x%y
 return g(y,r,t,s-q*t) if r else t
for _ in[0]*int(input()):
 s=input()
 a,b=f()
 h=g(26,a)
 print(''.join(z[h*(z.index(c)-b)%26]if c in z else c for c in s))

Python: # Edit : 2014/11/16
# Lang : Python3
# Time : 00.  s
# judge: not Accepted

# File: pc0021.py

from itertools import product


if __name__ == "__main__":

    mycode0 = "abcdefghijklmnopqrstuvwxyz"
    mycode1 = {
        "a": 0,
        "b": 1,
        "c": 2,
        "d": 3,
        "e": 4,
        "f": 5,
        "g": 6,
        "h": 7,
        "i": 8,
        "j": 9,
        "k": 10,
        "l": 11,
        "m": 12,
        "n": 13,
        "o": 14,
        "p": 15,
        "q": 16,
        "r": 17,
        "s": 18,
        "t": 19,
        "u": 20,
        "v": 21,
        "w": 22,
        "x": 23,
        "y": 24,
        "z": 25,
    }

    nset = int(input())
    for i in range(0, nset):

        inl = input()
        for a, b in product(range(1, 26, 2), range(1, 26)):
            outl = ""
            if a == 13:
                continue
            # print(a, b)

            for i in range(0, len(inl)):
                #if inl[i] == " ":
                #    outl += " "
                if inl[i] not in mycode1:
                    outl += inl[i]
                else:
                    decode = (a * mycode1[inl[i]] + b) % 26
                    outl += mycode0[decode]
            if "this" in outl or "that" in outl:
                print(outl)
                continue

                # i submit that there is another point of view
                # i submit that there is another point of view

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)

from sys import stdin
from string import ascii_lowercase
from itertools import count

def gcd(m, n):
    m, n = sorted([m, n])
    while n:
        m, n = n, m % n
    return m

def encode(char, A, B):
    return chr(((A * (ord(char) - 97) + B) % 26) + 97)

def solve(words):
    for a in (i for i in count(0) if gcd(i, 26) == 1):
        for b in range(26):
            for word in words:
                that = ''.join(encode(c, a, b) for c in 'that')
                if word == that:
                    return (a, b)
                this = ''.join(encode(c, a, b) for c in 'this')
                if word == this:
                    return (a, b)

def main():
    for _ in range(int(stdin.readline())):
        line = stdin.readline()
        a, b = solve([s for s in line.split() if len(s) == 4])
        d = {encode(c, a, b): c for c in ascii_lowercase}
        d[b' '] = b' '
        d[b'\n'] = ''
        print(''.join(d[c] for c in line))

if __name__ == '__main__':
    main()

Python: import sys
f = sys.stdin

import string

OFFSET = ord('a')

def to_gamma(c):
    return ord(c) - OFFSET

def from_gamma(gamma, alpha, beta):
    return chr((alpha * gamma + beta) % 26 + OFFSET) 

def affine(c, alpha, beta):
    return from_gamma(to_gamma(c), alpha, beta)


# g[0]==g[3]である前提
def search_that(w):
    b = to_gamma(w[2])
    for a in range(26):
        if w[0] == affine('t',a,b) and w[1] == affine('h',a,b):
            return a, b
    return -1, -1

def search_this(w):
    a = (to_gamma(w[0]) - to_gamma(w[3]) + 26) % 26
    for b in range(26):
        if w[0] == affine('t',a,b) and w[1] == affine('h',a,b) and w[2] == affine('i',a,b) and w[3] == affine('s',a,b):
            return a, b
    return -1, -1

def search(w):
    if w[0] == w[3]:
        return search_that(w)
    else:
        return search_this(w)

n = int(f.readline())
for i in range(n):
    line = f.readline().strip()
    words = [word for word in line.split() if len(word) == 4]
    for word in words:
        a, b = search(word)
        if a != -1:
            print(line.translate(str.maketrans(''.join([affine(c, a, b) for c in string.ascii_lowercase]), string.ascii_lowercase)))
            break

Python: # Aizu Problem 0040: Affine Cipher
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

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

def affine_decode(cipher, a_inv, b):
    message = ""
    for char in cipher:
        if 'a' <= char <= 'z':
            o = ord(char) - 97
            d = (a_inv * o - b) % 26
            message += chr(97 + d)
        else:
            message += char
    return message


N = int(input())
for n in range(N):
    cipher = input().strip()
    for b in range(26):
        for a_inv in A_INV:
            message = affine_decode(cipher, a_inv, b)
            if "this" in message or "that" in message:
                print(message)
                break

Python: def affine(word, alpha, beta):
    word = list(word)
    for i in range(len(word)):
        ascii = ((ord(word[i]) - ord('a')) * alpha + beta) % 26;
        word[i] = chr(ascii + ord('a'));
    return ''.join(word)
    
alphas = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25]

for x in range(int(input())):
    words = input().split(' ')
    for alpha in range(26):
        for beta in range(26):
            string = list(map(lambda x: affine(x, alpha, beta), words))
            if 'that' in string or 'this' in string:
                print(*string)
                break
        else:
            continue
        break