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
+18.3k Golang : Convert IPv4 address to decimal number(base 10) or integer
+5k Javascript : How to get width and height of a div?
+7.2k Golang : A simple forex opportunities scanner
+17.2k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+27.9k Golang : dial tcp: too many colons in address
+21.3k Golang : For loop continue,break and range
+7k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+5.3k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+6.5k Golang : How to get capacity of a slice or array?
+13.2k Golang : Get terminal width and height example
+26.7k Golang : Convert(cast) string to uint8 type and back to string
+26.8k Golang : Encrypt and decrypt data with AES crypto