// CheckDecode decodes a string that was encoded with CheckEncode and verifies the checksum.
438362
func CheckDecode(input string) (result []byte, version byte, err error) {
	decoded := Decode(input)
	if len(decoded) < 5 {
		return nil, 0, ErrInvalidFormat
	}
	version = decoded[0]
	var cksum [4]byte
	copy(cksum[:], decoded[len(decoded)-4:])
	if checksum(decoded[:len(decoded)-4]) != cksum {
		return nil, 0, ErrChecksum
	}
	payload := decoded[1 : len(decoded)-4]
	result = append(result, payload...)
	return
}
739777
func DecodeUint64(input string) (uint64, error) {
	raw, err := checkNumber(input)
	if err != nil {
		return 0, err
	}
	dec, err := strconv.ParseUint(raw, 16, 64)
	if err != nil {
		err = mapError(err)
	}
	return dec, err
}
973051
func ErrorCode(err error) string {
	if err == nil {
		return ""
	}

	e, ok := err.(*Error)
	if !ok {
		return EInternal
	}

	if e == nil {
		return ""
	}

	if e.Code != "" {
		return e.Code
	}

	if e.Err != nil {
		return ErrorCode(e.Err)
	}

	return EInternal
}
292332
func (e *encoding) decode(s string) uint64 {
	x := uint64(0)
	for i := 0; i < len(s); i++ {
		x = (x << 5) | uint64(e.dec[s[i]])
	}
	return x
}
818190
func CheckEncode(input []byte, version byte) string {
	b := make([]byte, 0, 1+len(input)+4)
	b = append(b, version)
	b = append(b, input[:]...)
	cksum := checksum(b)
	b = append(b, cksum[:]...)
	return Encode(b)
}
1199220
func (node *SQLVal) HexDecode() ([]byte, error) {
	dst := make([]byte, hex.DecodedLen(len([]byte(node.Val))))
	_, err := hex.Decode(dst, []byte(node.Val))
	if err != nil {
		return nil, err
	}
	return dst, err
}
726049
func SQLDecode(str string, password string) (string, error) {
	var sc sqlCrypt

	strByte := []byte(str)
	passwdByte := []byte(password)

	sc.init(passwdByte, len(passwdByte))
	sc.decode(strByte, len(strByte))

	return string(strByte), nil
}
745449
func Check(password, key string) bool {
	err := sha512crypt.New().Verify(key, []byte(password))
	return err == nil
}
961046
func Encode(content string, includeChecksum bool, fullASCIIMode bool) (barcode.BarcodeIntCS, error) {
	if fullASCIIMode {
		var err error
		content, err = prepare(content)
		if err != nil {
			return nil, err
		}
	} else if strings.ContainsRune(content, '*') {
		return nil, errors.New("invalid data! try full ascii mode")
	}

	data := "*" + content
	if includeChecksum {
		data += getChecksum(content)
	}
	data += "*"

	result := new(utils.BitList)

	for i, r := range data {
		if i != 0 {
			result.AddBit(false)
		}

		info, ok := encodeTable[r]
		if !ok {
			return nil, errors.New("invalid data! try full ascii mode")
		}
		result.AddBit(info.data...)
	}

	checkSum, err := strconv.ParseInt(getChecksum(content), 10, 64)
	if err != nil {
		checkSum = 0
	}
	return utils.New1DCodeIntCheckSum(barcode.TypeCode39, content, result, int(checkSum)), nil
}
696829
func Decode(code *string) error {
	// Don't decode empty strings
	if *code == "" {
		return nil
	}
	unhexedBytes, err := hex.DecodeString(*code)
	if err != nil {
		return err
	}
	buf := bytes.NewBuffer(unhexedBytes)
	decompressorReader := flate.NewReader(buf)
	decompressedBytes, err := ioutil.ReadAll(decompressorReader)
	decompressorReader.Close()
	if err != nil {
		return err
	}
	*code = string(decompressedBytes)
	return nil
}
330863
func xorChecksum(s string) string {
	var checksum uint8
	for i := 0; i < len(s); i++ {
		checksum ^= s[i]
	}
	return fmt.Sprintf("%02X", checksum)
}
969570
func parseCheckIndex(input string) (uint64, bool, error) {
	if input == "" {
		return 0, false, nil
	}

	u, err := strconv.ParseUint(input, 10, 64)
	return u, true, err
}
1086115
func b58decode(s string) (b []byte, err error) {
	/* See https://en.bitcoin.it/wiki/Base58Check_encoding */

	const BITCOIN_BASE58_TABLE = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"

	/* Initialize */
	x := big.NewInt(0)
	m := big.NewInt(58)

	/* Convert string to big int */
	for i := 0; i < len(s); i++ {
		b58index := strings.IndexByte(BITCOIN_BASE58_TABLE, s[i])
		if b58index == -1 {
			return nil, fmt.Errorf("Invalid base-58 character encountered: '%c', index %d.", s[i], i)
		}
		b58value := big.NewInt(int64(b58index))
		x.Mul(x, m)
		x.Add(x, b58value)
	}

	/* Convert big int to big endian bytes */
	b = x.Bytes()

	return b, nil
}
110153
func (d *Decoder) DecodeInt64() (int64, error) {
	c, err := d.readCode()
	if err != nil {
		return 0, err
	}
	return d.int(c)
}
471916
func (d *Context) Base64Decode(index int) {
	C.duk_base64_decode(d.duk_context, C.duk_idx_t(index))
}
1333769
func Encode(in []byte) (string, error) {
	return b64.StdEncoding.EncodeToString(in), nil
}
643618
func decodeString(in string) (string, error) {
	out := make([]byte, len(in))
	o := 0
	for i := 0; i < len(in); {
		if in[i] == '\\' {
			i++
			switch in[i] {
			case 'u':
				i++
				utf8rune := 0
				for j := 0; j < 4; j++ {
					switch {
					case in[i] >= '0' && in[i] <= '9':
						utf8rune = (utf8rune << 4) + int(in[i]) - '0'
						break
					case in[i] >= 'a' && in[i] <= 'f':
						utf8rune = (utf8rune << 4) + 10 + int(in[i]) - 'a'
						break
					case in[i] >= 'A' && in[i] <= 'F':
						utf8rune = (utf8rune << 4) + 10 + int(in[i]) - 'A'
						break
					default:
						return "", ErrMalformedUtf8Encoding
					}
					i++
				}
				bytes := make([]byte, utf8.RuneLen(rune(utf8rune)))
				bytesWritten := utf8.EncodeRune(bytes, rune(utf8rune))
				for j := 0; j < bytesWritten; j++ {
					out[o] = bytes[j]
					o++
				}
				continue
			case 't':
				out[o] = '\t'
				o++
				i++
				continue
			case 'r':
				out[o] = '\r'
				o++
				i++
				continue
			case 'n':
				out[o] = '\n'
				o++
				i++
				continue
			case 'f':
				out[o] = '\f'
				o++
				i++
				continue
			}
			out[o] = in[i]
			o++
			i++
			continue
		}
		out[o] = in[i]
		o++
		i++
	}

	return string(out[0:o]), nil
}