Skip to content

Instantly share code, notes, and snippets.

@selfup
Created September 17, 2018 21:00
Show Gist options
  • Save selfup/a3a489e4f7579286febd13e27af87fe4 to your computer and use it in GitHub Desktop.
Save selfup/a3a489e4f7579286febd13e27af87fe4 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"strings"
"sync"
)
func main() {
input := ""
output := ""
osArgsLength := len(os.Args)
if osArgsLength > 1 && osArgsLength == 3 {
input = os.Args[1]
output = os.Args[2]
} else {
fmt.Println("Please give input file as first arg and output file as second arg")
return
}
fileBytes, err := ioutil.ReadFile(input)
if err != nil {
fmt.Print(err)
}
str := string(fileBytes)
strLength := len(str)
var result []string
var mutex = &sync.Mutex{}
var wg sync.WaitGroup
wg.Add(strLength)
for i := 0; i < strLength; i++ {
go func(i int) {
defer wg.Done()
char := str[i]
random := rand.Intn(1000)
mutex.Lock()
obf := string(fmt.Sprintf("%v%v", string(char), random))
result = append(result, obf)
mutex.Unlock()
}(i)
}
wg.Wait()
resultStr := strings.Join(result, "")
outputBytes := []byte(resultStr)
err = ioutil.WriteFile(output, outputBytes, 0644)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment