<commit_before>package xxtea

import (
	"crypto/cipher"
	"strconv"
)

type KeySizeError int

func (k KeySizeError) Error() string {
	return "xxtea: invalid key size: " + strconv.Itoa(int(k))
}

type BlockSizeError int

func (b BlockSizeError) Error() string {
	return "xxtea: invalid block size: " + strconv.Itoa(int(b))
}

// Internal state for the XXTEA block cipher.
type _XXTEA struct {
	blockSize int
	key       [4]uint32
}

func (x *_XXTEA) BlockSize() int {
	return x.blockSize
}

func (x *_XXTEA) Encrypt(dst, src []byte) {
	// XXX: There is no block size checking here.

	// Convert bytes to uint32s.
	srcInts := bytesToUint32s(src)

	// Create destination buffer.
	dstInts := make([]uint32, len(dst)/4)

	// Encrypt.
	encode(dstInts, srcInts, x.key[:])

	// Convert back to bytes.
	byteResult := uint32sToBytes(dstInts)

	// Copy to result.
	copy(dst, byteResult)
}

func (x *_XXTEA) Decrypt(dst, src []byte) {
	// XXX: There is no block size checking here.

	// Convert bytes to uint32s.
	srcInts := bytesToUint32s(src)

	// Create destination buffer.
	dstInts := make([]uint32, len(dst)/4)

	// Decrypt.
	decode(dstInts, srcInts, x.key[:])

	// Convert back to bytes.
	byteResult := uint32sToBytes(dstInts)

	// Copy to result.
	copy(dst, byteResult)
}

// New creates and returns a new cipher.Block.
// Argument key should be 128 bits (16 bytes).
// Argument blockSize should be a block size in bytes. XXTEA supports
// arbitrarily-sized blocks that are at least 8 bytes long, with a length
// that is a multiple of 4 bytes.
func New(key []byte, blockSize int) (cipher.Block, error) {
	// XXTEA uses a 128 bit (16 byte) key size.
	if len(key) != 16 {
		return nil, KeySizeError(len(key))
	}

	// XXTEA supports arbitrary block sizes that are 64 bits or larger, and multiples of 32 bits.
	if blockSize < 8 || (blockSize%4) != 0 {
		return nil, BlockSizeError(blockSize)
	}

	var k = make([]uint32, 4)
	k = bytesToUint32s(key)

	var k2 [4]uint32
	copy(k2[:], k)

	x := &_XXTEA{
		key:       k2,<commit_msg>Rename New() to NewCipher() to match convention.<commit_after>package xxtea

import (
	"crypto/cipher"
	"strconv"
)

type KeySizeError int

func (k KeySizeError) Error() string {
	return "xxtea: invalid key size: " + strconv.Itoa(int(k))
}

type BlockSizeError int

func (b BlockSizeError) Error() string {
	return "xxtea: invalid block size: " + strconv.Itoa(int(b))
}

// Internal state for the XXTEA block cipher.
type _XXTEA struct {
	blockSize int
	key       [4]uint32
}

func (x *_XXTEA) BlockSize() int {
	return x.blockSize
}

func (x *_XXTEA) Encrypt(dst, src []byte) {
	// XXX: There is no block size checking here.

	// Convert bytes to uint32s.
	srcInts := bytesToUint32s(src)

	// Create destination buffer.
	dstInts := make([]uint32, len(dst)/4)

	// Encrypt.
	encode(dstInts, srcInts, x.key[:])

	// Convert back to bytes.
	byteResult := uint32sToBytes(dstInts)

	// Copy to result.
	copy(dst, byteResult)
}

func (x *_XXTEA) Decrypt(dst, src []byte) {
	// XXX: There is no block size checking here.

	// Convert bytes to uint32s.
	srcInts := bytesToUint32s(src)

	// Create destination buffer.
	dstInts := make([]uint32, len(dst)/4)

	// Decrypt.
	decode(dstInts, srcInts, x.key[:])

	// Convert back to bytes.
	byteResult := uint32sToBytes(dstInts)

	// Copy to result.
	copy(dst, byteResult)
}

// New creates and returns a new cipher.Block.
// Argument key should be 128 bits (16 bytes).
// Argument blockSize should be a block size in bytes. XXTEA supports
// arbitrarily-sized blocks that are at least 8 bytes long, with a length
// that is a multiple of 4 bytes.
func NewCipher(key []byte, blockSize int) (cipher.Block, error) {
	// XXTEA uses a 128 bit (16 byte) key size.
	if len(key) != 16 {
		return nil, KeySizeError(len(key))
	}

	// XXTEA supports arbitrary block sizes that are 64 bits or larger, and multiples of 32 bits.
	if blockSize < 8 || (blockSize%4) != 0 {
		return nil, BlockSizeError(blockSize)
	}

	var k = make([]uint32, 4)
	k = bytesToUint32s(key)

	var k2 [4]uint32
	copy(k2[:], k)

	x := &_XXTEA{
		key:       k2,
{'fraction_non_alphanumeric': 0.1278527607361963, 'fraction_numerical': 0.026012269938650308, 'mean_word_length': 3.498896247240618, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3886613', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1465, 'n_words': 489}