func LenTritsFromTrytes(n int) int {
	return n * tritsPerTryte
}
LenTritsFromTrytes returns the number of trits for n trytes
package trinary
import "errors"
const (
	tryteAlphabet      = "9ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	tritsPerByte       = 5
	tritsPerTryte      = 3
	tritRadix     int8 = 3
	maxTritValue  int8 = (tritRadix - 1) / 2
	minTritValue  int8 = -maxTritValue
)
var (
	tryteRuneIndex = make(map[rune]int, len(tryteAlphabet))
	bytesToTrits   [243][tritsPerByte]int8
	trytesToTrits  [27][tritsPerTryte]int8
)
var (
	errBufferTooSmall = errors.New("buffer too small")
	errMultipleThree  = errors.New("buffer size must be a multiple of 3")
)
func init() {
	var trits [tritsPerByte]int8
	for i := 0; i < 243; i++ {
		copy(bytesToTrits[i][:], trits[:tritsPerByte])
		incrementTrits(trits[:], tritsPerByte)
	}
	for i := 0; i < 27; i++ {
		copy(trytesToTrits[i][:], trits[:tritsPerTryte])
		incrementTrits(trits[:], tritsPerTryte)
	}
	for i, c := range tryteAlphabet {
		tryteRuneIndex[c] = i
	}
}
func incrementTrits(trits []int8, n int) {
	for i := 0; i < n; i++ {
		trits[i]++
		if trits[i] > maxTritValue {
			trits[i] = minTritValue
		} else {
			break
		}
	}
}
func Validate(a []int8) bool {
	for _, v := range a {
		if !validTrit(v) {
			return false
		}
	}
	return true
}
func Trits(dst []int8, src []byte) (int, error) {
	n := len(src) * tritsPerByte
	if len(dst) < n {
		return 0, errBufferTooSmall
	}
	offset := 0
	for i := 0; i < len(src) && offset < n; i++ {
		x := int(int8(src[i]))  
		if x < 0 {
			x += len(bytesToTrits)
		}
		o := tritsPerByte
		j := n - offset
		if j < tritsPerByte {
			o = j
		}
		if len(dst) < offset+o {
			return 0, errBufferTooSmall
		}
		copy(dst[offset:offset+o], bytesToTrits[x][0:o])
		offset += tritsPerByte
	}
	for offset < n {
		dst[offset] = 0
		offset++
	}
	return n, nil
}
func TritsFromTrytes(dst []int8, src string) (int, error) {
	n := LenTritsFromTrytes(len(src))
	if len(dst) < n {
		return 0, errBufferTooSmall
	}
	for i, c := range src {
		j := i * tritsPerTryte
		copy(dst[j:j+tritsPerTryte], trytesToTrits[tryteRuneIndex[c]][:])
	}
	return n, nil
}
func validTrit(v int8) bool {
	return v >= -1 && v <= 1
}
func LenBytes(n int) int {
	return (n + tritsPerByte - 1) / tritsPerByte
}
func LenTrits(n int) int {
	return n * tritsPerByte
}