Skip to content

Commit

Permalink
feat: add fuzzing for cipher/xor (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltay committed Oct 3, 2022
1 parent eaa2be2 commit 4d9b1e4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cipher/xor/xor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xor

import (
"bytes"
"fmt"
"reflect"
"testing"
Expand Down Expand Up @@ -103,3 +104,14 @@ func TestXorCipherDecrypt(t *testing.T) {
})
}
}

func FuzzXOR(f *testing.F) {
f.Add([]byte("The Quick Brown Fox Jumps over the Lazy Dog."), byte('X'))
f.Fuzz(func(t *testing.T, input []byte, key byte) {
cipherText := Encrypt(key, input)
result := Decrypt(key, cipherText)
if !bytes.Equal(input, result) {
t.Errorf("Before: %s, after: %s, key: %d", input, result, key)
}
})
}

0 comments on commit 4d9b1e4

Please sign in to comment.