Golang : Frobnicate or tweaking a string example
A simple example of how to frobnicate(tweaking) a string with UTF-8 characters. Useful in obscuring plain text in embedded in executable binary file if you do not want the text to be visible to someone viewing your executable file with a hex editor. To achieve that, first frobnicate the text first into a obfuscated(frobnicated) text and then use the frobnicate function again on the obfuscated text during runtime to convert to readable text.
Here you go!
package main
import (
"fmt"
"strings"
"unicode"
"unicode/utf8"
)
// frobnicate/tweak a string
func frobnicate(input string) string {
var result []string
for _,i := range input {
switch {
case unicode.IsSpace(i):
result = append(result, " ")
// uncomment to frob the digits
//case unicode.IsNumber(i):
// result = append(result, string(rune(i)))
case utf8.ValidRune(i):
result = append(result, string(rune(i) ^ 42))
}
}
return strings.Join(result,"")
}
func main() {
text := "жѳМѭњЂЯёЧВ 一二三 handle alphabets = ขอพฮศโำฐเฦ abc世界你好123 ペツワケザユプルヂザ"
fmt.Println(text)
fmt.Println(frobnicate(text))
fmt.Println("Invertible test:")
fmt.Println(frobnicate(frobnicate(text)))
}
References:
https://www.socketloop.com/tutorials/golang-rot32768-rotate-by-0x80-utf-8-strings-example
See also : Golang : Embed secret text string into binary(executable) file
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+29k Golang : Login(Authenticate) with Facebook example
+21.3k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+7.3k Golang : Example of how to detect which type of script a word belongs to
+19.1k Golang : Close channel after ticker stopped example
+7.2k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+9.1k Golang : Read file with ioutil
+5.1k Golang : Display advertisement images or strings on random order
+5.2k Golang : Detect words using using consecutive letters in a given string
+12.4k Golang : Convert int(year) to time.Time type
+5.3k Fix fatal error: evacuation not done in time problem
+5.7k Golang : Missing Subversion command
+9.7k Golang : Check a web page existence with HEAD request example