Created
September 17, 2018 21:00
-
-
Save selfup/a3a489e4f7579286febd13e27af87fe4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
"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