You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

72 lines
1.6 KiB

package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
// so far letters and numbers work, symbols and punctuation are not ok
// input file has data vertically, I assume it must be switches to horisontal...?
// example command: go run . --reverse=inputfile.txt
func main() {
args_slice := os.Args[1:]
reference_file := "shadow.txt"
var file_name string
for i, name := range args_slice {
if strings.Contains(name, "--reverse=") { // looking for flag
file_name = name[10:]
break
}
if len(args_slice)-1 == i {
fmt.Println("EX: go run . something standard --reverse=<fileName>")
}
}
input, err1 := ioutil.ReadFile(file_name) // reading graphic input file
text_slices := strings.Split(string(input), "\n")
if err1 != nil {
fmt.Println("file does not exist")
os.Exit(1)
}
reference, err2 := ioutil.ReadFile(reference_file) // reading example file standard-shadow-thinkerboy
reference_slices := strings.Split(string(reference), "\n")
if err2 != nil {
fmt.Println("reference not found")
os.Exit(2)
}
indexes := make([]int, 0) // contains indexes to reverse-calculate ascii values
for x := 0; x < len(text_slices)-9; x += 9 {
for i := 0; i < len(reference_slices)-9; i += 9 {
for y := 0; y < 9; y++ {
if text_slices[x+y] == reference_slices[i+y] && y != 8 {
continue
} else if y == 8 && text_slices[y] == reference_slices[i+y] {
indexes = append(indexes, i)
break
} else {
break
}
}
}
}
// fmt.Println(len(indexes))
// fmt.Println(indexes)
var str_output string
for id := range indexes {
str_output += string(byte(indexes[id]/9 + 32))
}
fmt.Println(str_output)
}