Last active
July 13, 2016 17:40
-
-
Save caelifer/d4328bcca8828dd6f3a04ca43894b853 to your computer and use it in GitHub Desktop.
This file contains 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" | |
"math/rand" | |
) | |
func main() { | |
for i := 0; i < 4; i++ { | |
if i > 0 { | |
fmt.Println() | |
} | |
fmt.Println(NewPayload(2 * lineLen * (i + 1))) | |
} | |
} | |
const lineLen = 64 | |
type Payload []byte | |
func NewPayload(size int) Payload { | |
p := Payload(make([]byte, size)) | |
alphabet := [...]byte{ | |
'0', '1', '2', '3', | |
'4', '5', '6', '7', | |
'8', '9', 'a', 'b', | |
'c', 'd', 'e', 'f', | |
'g', 'h', 'i', 'j', | |
'k', 'l', 'm', 'n', | |
'o', 'p', 'q', 'r', | |
} | |
n := len(alphabet) | |
for i := 0; i < size; i++ { | |
p[i] = alphabet[rand.Intn(n)] | |
} | |
return p | |
} | |
func (p Payload) String() string { | |
n := len(p) | |
out := make([]byte, 0, n*(1+1/lineLen)-1) | |
for i := 0; i < n; i += lineLen { | |
if i > 0 { | |
// Add new line | |
out = append(out, '\n') | |
} | |
out = append(out, p[i:i+lineLen]...) | |
} | |
return string(out) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Live code - https://play.golang.org/p/guS2QeQ-uH
Sample output: