rot13logic.go 1.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
package rot13adl

import (
	"strings"
)

var replaceTable = []string{
	"A", "N",
	"B", "O",
	"C", "P",
	"D", "Q",
	"E", "R",
	"F", "S",
	"G", "T",
	"H", "U",
	"I", "V",
	"J", "W",
	"K", "X",
	"L", "Y",
	"M", "Z",
	"N", "A",
	"O", "B",
	"P", "C",
	"Q", "D",
	"R", "E",
	"S", "F",
	"T", "G",
	"U", "H",
	"V", "I",
	"W", "J",
	"X", "K",
	"Y", "L",
	"Z", "M",
	"a", "n",
	"b", "o",
	"c", "p",
	"d", "q",
	"e", "r",
	"f", "s",
	"g", "t",
	"h", "u",
	"i", "v",
	"j", "w",
	"k", "x",
	"l", "y",
	"m", "z",
	"n", "a",
	"o", "b",
	"p", "c",
	"q", "d",
	"r", "e",
	"s", "f",
	"t", "g",
	"u", "h",
	"v", "i",
	"w", "j",
	"x", "k",
	"y", "l",
	"z", "m",
}
var unreplaceTable = func() []string {
	v := make([]string, len(replaceTable))
	for i := 0; i < len(replaceTable); i += 2 {
		v[i] = replaceTable[i+1]
		v[i+1] = replaceTable[i]
	}
	return v
}()

// rotate transforms from the logical content to the raw content.
func rotate(s string) string {
	return strings.NewReplacer(replaceTable...).Replace(s)
}

// unrotate transforms from the raw content to the logical content.
func unrotate(s string) string {
	return strings.NewReplacer(unreplaceTable...).Replace(s)
}