26 lines
490 B
Go
26 lines
490 B
Go
|
package xorencrypt
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestXOR(t *testing.T) {
|
||
|
msg := "test"
|
||
|
key := "key"
|
||
|
enc := xor([]byte(msg), []byte(key))
|
||
|
dec := xor([]byte(enc), []byte(key))
|
||
|
fmt.Printf("%s -> %d -> %s\n", msg, enc, dec)
|
||
|
}
|
||
|
|
||
|
func TestEncrypt(t *testing.T) {
|
||
|
msg := "test"
|
||
|
key := "key"
|
||
|
enc := Encrypt(msg, key)
|
||
|
dec, _ := Decrypt(enc, key)
|
||
|
fmt.Printf("%s -> %s -> %s\n", msg, enc, dec)
|
||
|
|
||
|
decErr, _ := Decrypt(enc, "wrongKey")
|
||
|
fmt.Printf("%s -> %s -> %s\n", msg, enc, decErr)
|
||
|
}
|