Last active
April 6, 2020 17:44
-
-
Save pyperanger/91568c5b806b07337ff20ba19b326ceb to your computer and use it in GitHub Desktop.
Golang Expr Obfuscation Gval Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
"github.com/PaesslerAG/gval" | |
) | |
var ( | |
dic = strings.NewReplacer( | |
"Zero","0", | |
"One","1", | |
"Two","2", | |
"Three","3", | |
"Four","4", | |
"Five","5", | |
"Six","6", | |
"Seven","7", | |
"Eight","8", | |
"Nine","9", | |
) | |
) | |
func convert(m string) (string) { | |
return dic.Replace(m); | |
} | |
func calc(m string) (int){ | |
// ref: https://godoc.org/github.com/PaesslerAG/gval#example-Evaluate--Arithmetic | |
value, err := gval.Evaluate(m, map[string]interface{}{}) | |
if err != nil { | |
panic(err) | |
} | |
return int(value.(float64)) | |
} | |
func main(){ | |
// Numbers in format string | |
magic := "(Eight5TwoThree^Three5Zero)+"; | |
magic += "(FourEightEightSeven^SevenFiveNine)+"; | |
magic += "(Eight5TwoThree^Three5Zero)+"; | |
magic += "(FourEightEightSeven^SevenFiveNine)"; | |
fmt.Printf("Original: %s\n",magic); | |
magic = convert(magic); | |
fmt.Printf("Replacd: %s\n",magic); | |
magic_number := calc(magic); | |
fmt.Print("Result: ", magic_number, "\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment