From 850380bf6f8ce8671e313ca2857f131b5b1f47f2 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Fri, 11 Jan 2019 18:27:29 +0100 Subject: [PATCH] add -shuffle flag --- main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.go b/main.go index 3256c75..0fa560a 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( _ "image/jpeg" _ "image/png" "log" + "math/rand" "net" _ "net/http/pprof" "os" @@ -24,6 +25,7 @@ var image_offsety = flag.Int("yoffset", 0, "Offset of posted image from top bord var connections = flag.Int("connections", 10, "Number of simultaneous connections/threads. Each Thread posts a subimage") var address = flag.String("host", "127.0.0.1:1337", "Server address") var runtime = flag.String("runtime", "1", "Runtime in Minutes") +var shuffle = flag.Bool("shuffle", false, "pixel send ordering") func main() { flag.Parse() @@ -50,6 +52,10 @@ func main() { // Generate and split messages into equal chunks commands := genCommands(readImage(*image_path), *image_offsetx, *image_offsety) + if *shuffle { + shuffleCommands(commands) + } + commandGroups := chunkCommands(commands, *connections) for _, messages := range commandGroups { go bomb(messages) @@ -138,3 +144,10 @@ func chunkCommands(commands [][]byte, numChunks int) [][][]byte { } return chunks } + +func shuffleCommands(slice [][]byte) { + for i := range slice { + j := rand.Intn(i + 1) + slice[i], slice[j] = slice[j], slice[i] + } +}