func NewCipher(key []byte) (*Cipher, error) {
	keylen := len(key)
	if keylen != 16 && keylen != 24 && keylen != 32 {
		return nil, KeySizeError(keylen)
	}
	k := keylen / 8
	var S [4 * 4]byte
	for i := 0; i < k; i++ {
		for j, rsRow := range rs {
			for k, rsVal := range rsRow {
				S[4*i+j] ^= gfMult(key[8*i+k], rsVal, rsPolynomial)
			}
		}
	}
	c := new(Cipher)
	var tmp [4]byte
	for i := byte(0); i < 20; i++ {
		for j := range tmp {
			tmp[j] = 2 * i
		}
		A := h(tmp[:], key, 0)
		for j := range tmp {
			tmp[j] = 2*i + 1
		}
		B := h(tmp[:], key, 1)
		B = rol(B, 8)
		c.k[2*i] = A + B
		c.k[2*i+1] = rol(2*B+A, 9)
	}
	switch k {
	case 2:
		for i := range c.s[0] {
			c.s[0][i] = mdsColumnMult(sbox[1][sbox[0][sbox[0][byte(i)]^S[0]]^S[4]], 0)
			c.s[1][i] = mdsColumnMult(sbox[0][sbox[0][sbox[1][byte(i)]^S[1]]^S[5]], 1)
			c.s[2][i] = mdsColumnMult(sbox[1][sbox[1][sbox[0][byte(i)]^S[2]]^S[6]], 2)
			c.s[3][i] = mdsColumnMult(sbox[0][sbox[1][sbox[1][byte(i)]^S[3]]^S[7]], 3)
		}
	case 3:
		for i := range c.s[0] {
			c.s[0][i] = mdsColumnMult(sbox[1][sbox[0][sbox[0][sbox[1][byte(i)]^S[0]]^S[4]]^S[8]], 0)
			c.s[1][i] = mdsColumnMult(sbox[0][sbox[0][sbox[1][sbox[1][byte(i)]^S[1]]^S[5]]^S[9]], 1)
			c.s[2][i] = mdsColumnMult(sbox[1][sbox[1][sbox[0][sbox[0][byte(i)]^S[2]]^S[6]]^S[10]], 2)
			c.s[3][i] = mdsColumnMult(sbox[0][sbox[1][sbox[1][sbox[0][byte(i)]^S[3]]^S[7]]^S[11]], 3)
		}
	default:
		for i := range c.s[0] {
			c.s[0][i] = mdsColumnMult(sbox[1][sbox[0][sbox[0][sbox[1][sbox[1][byte(i)]^S[0]]^S[4]]^S[8]]^S[12]], 0)
			c.s[1][i] = mdsColumnMult(sbox[0][sbox[0][sbox[1][sbox[1][sbox[0][byte(i)]^S[1]]^S[5]]^S[9]]^S[13]], 1)
			c.s[2][i] = mdsColumnMult(sbox[1][sbox[1][sbox[0][sbox[0][sbox[0][byte(i)]^S[2]]^S[6]]^S[10]]^S[14]], 2)
			c.s[3][i] = mdsColumnMult(sbox[0][sbox[1][sbox[1][sbox[0][sbox[1][byte(i)]^S[3]]^S[7]]^S[11]]^S[15]], 3)
		}
	}
	return c, nil
}
NewCipher creates and returns a Cipher.
The key argument should be the Twofish key, 16, 24 or 32 bytes.
package twofish  
import "strconv"
const BlockSize = 16
const mdsPolynomial = 0x169  
const rsPolynomial = 0x14d   
type Cipher struct {
	s [4][256]uint32
	k [40]uint32
}
type KeySizeError int
func (k KeySizeError) Error() string {
	return "crypto/twofish: invalid key size " + strconv.Itoa(int(k))
}