package tscipher

import ()

type XOR struct {
	key []byte
}

func (this *XOR) Decrypt(data []byte) (decrypted []byte, err error) {
	decrypted = make([]byte, len(data))
	for i := 0; i < len(data); i++ {
		decrypted[i] = data[i] ^ this.key[i%len(this.key)]
	}
	err = nil
	return
}

func (this *XOR) Encrypt(data []byte) (encryped []byte, err error) {
	encryped = make([]byte, len(data))
	for i := 0; i < len(data); i++ {
		encryped[i] = data[i] ^ this.key[i%len(this.key)]
	}
	err = nil
	return
}

func NewXOR(key []byte) (cipher Cipher) {
	return &XOR{
		key: key,
	}
}
