Skip to main content
deleted 12 characters in body
Source Link
peterSO
  • 3.5k
  • 13
  • 14

For example,

package main

import (
    "fmt"
    "math/rand"
    "time"
)

func padWithRandomBytes(b []byte) []byte {
    s := 5 + rand.Intn(5+1)
    e := 5 + rand.Intn(5+1)
    slicer := make([]byte, s+len(b)+e)
    copy(slice[sr[s:], b)
    return slicer
}

func main() {
    rand.Seed(time.Now().UnixNano())
    b := []byte{1, 2, 3}
    fmt.Println(len(b), b)
    sr := padWithRandomBytes(b)
    fmt.Println(len(sr), sr)
}

Output (random):

3 [1 2 3]
20 [0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 0]

3 [1 2 3]
15 [0 0 0 0 0 0 1 2 3 0 0 0 0 0 0]

For example,

package main

import (
    "fmt"
    "math/rand"
    "time"
)

func padWithRandomBytes(b []byte) []byte {
    s := 5 + rand.Intn(5+1)
    e := 5 + rand.Intn(5+1)
    slice := make([]byte, s+len(b)+e)
    copy(slice[s:], b)
    return slice
}

func main() {
    rand.Seed(time.Now().UnixNano())
    b := []byte{1, 2, 3}
    fmt.Println(len(b), b)
    s := padWithRandomBytes(b)
    fmt.Println(len(s), s)
}

Output (random):

3 [1 2 3]
20 [0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 0]

3 [1 2 3]
15 [0 0 0 0 0 0 1 2 3 0 0 0 0 0 0]

For example,

package main

import (
    "fmt"
    "math/rand"
    "time"
)

func padWithRandomBytes(b []byte) []byte {
    s := 5 + rand.Intn(5+1)
    e := 5 + rand.Intn(5+1)
    r := make([]byte, s+len(b)+e)
    copy(r[s:], b)
    return r
}

func main() {
    rand.Seed(time.Now().UnixNano())
    b := []byte{1, 2, 3}
    fmt.Println(len(b), b)
    r := padWithRandomBytes(b)
    fmt.Println(len(r), r)
}

Output (random):

3 [1 2 3]
20 [0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 0]

3 [1 2 3]
15 [0 0 0 0 0 0 1 2 3 0 0 0 0 0 0]
bug fix
Source Link
peterSO
  • 3.5k
  • 13
  • 14

For example,

package main

import (
    "fmt"
    "math/rand"
    "time"
)

func padWithRandomBytes(b []byte) []byte {
    s := 105 -+ rand.Intn(55+1)
    e := 105 -+ rand.Intn(55+1)
    slice := make([]byte, s+len(b)+e)
    copy(slice[s:], b)
    return slice
}

func main() {
    rand.Seed(time.Now().UnixNano())
    b := []byte{1, 2, 3}
    fmt.Println(len(b), b)
    s := padWithRandomBytes(b)
    fmt.Println(len(s), s)
}

Output (random):

3 [1 2 3]
20 [0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 0]

3 [1 2 3]
15 [0 0 0 0 0 0 1 2 3 0 0 0 0 0 0]

For example,

package main

import (
    "fmt"
    "math/rand"
    "time"
)

func padWithRandomBytes(b []byte) []byte {
    s := 10 - rand.Intn(5)
    e := 10 - rand.Intn(5)
    slice := make([]byte, s+len(b)+e)
    copy(slice[s:], b)
    return slice
}

func main() {
    rand.Seed(time.Now().UnixNano())
    b := []byte{1, 2, 3}
    fmt.Println(len(b), b)
    s := padWithRandomBytes(b)
    fmt.Println(len(s), s)
}

Output (random):

3 [1 2 3]
20 [0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 0]

3 [1 2 3]
15 [0 0 0 0 0 0 1 2 3 0 0 0 0 0 0]

For example,

package main

import (
    "fmt"
    "math/rand"
    "time"
)

func padWithRandomBytes(b []byte) []byte {
    s := 5 + rand.Intn(5+1)
    e := 5 + rand.Intn(5+1)
    slice := make([]byte, s+len(b)+e)
    copy(slice[s:], b)
    return slice
}

func main() {
    rand.Seed(time.Now().UnixNano())
    b := []byte{1, 2, 3}
    fmt.Println(len(b), b)
    s := padWithRandomBytes(b)
    fmt.Println(len(s), s)
}

Output (random):

3 [1 2 3]
20 [0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 0]

3 [1 2 3]
15 [0 0 0 0 0 0 1 2 3 0 0 0 0 0 0]
Source Link
peterSO
  • 3.5k
  • 13
  • 14

For example,

package main

import (
    "fmt"
    "math/rand"
    "time"
)

func padWithRandomBytes(b []byte) []byte {
    s := 10 - rand.Intn(5)
    e := 10 - rand.Intn(5)
    slice := make([]byte, s+len(b)+e)
    copy(slice[s:], b)
    return slice
}

func main() {
    rand.Seed(time.Now().UnixNano())
    b := []byte{1, 2, 3}
    fmt.Println(len(b), b)
    s := padWithRandomBytes(b)
    fmt.Println(len(s), s)
}

Output (random):

3 [1 2 3]
20 [0 0 0 0 0 0 0 0 1 2 3 0 0 0 0 0 0 0 0 0]

3 [1 2 3]
15 [0 0 0 0 0 0 1 2 3 0 0 0 0 0 0]