30 lines
596 B
Go
30 lines
596 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)
|
|
|
|
encD := Encrypt(msg, "")
|
|
decD, _ := Decrypt(encD, "")
|
|
fmt.Printf("%s -> %s -> %s\n", msg, encD, decD)
|
|
}
|