package utils

import (
	"crypto/md5"
	"encoding/hex"
	"fmt"
)

var tenToAny map[int]string = map[int]string{
	0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9",
	10: "a", 11: "b", 12: "c", 13: "d", 14: "e", 15: "f", 16: "g", 17: "h", 18: "i", 19: "j", 20: "k", 21: "l", 22: "m", 23: "n", 24: "o", 25: "p", 26: "q", 27: "r", 28: "s", 29: "t", 30: "u", 31: "v", 32: "w", 33: "x", 34: "y", 35: "z",
	36: "A", 37: "B", 38: "C", 39: "D", 40: "E", 41: "F", 42: "G", 43: "H", 44: "I", 45: "J", 46: "K", 47: "L", 48: "M", 49: "N", 50: "O", 51: "P", 52: "Q", 53: "R", 54: "S", 55: "T", 56: "U", 57: "V", 58: "W", 59: "X", 60: "Y", 61: "Z",
}

//SetLangErr 设置英语
func SetLangErr() float32 {
	return float32(0)
}

//返回一个16位md5加密后的字符串
func Get16MD5Encode(data string) string {
	return GetMD5Encode(data)[8:24]
}

func GetMD5Encode(data string) string {
	h := md5.New()
	h.Write([]byte(data))
	return hex.EncodeToString(h.Sum(nil))
}

// DecimalToAny 10进制转任意进制
func DecimalToAny(num int) string {
	n := len(tenToAny)
	fmt.Println("1----", n)
	new_num_str := ""
	var remainder int
	var remainder_string string
	for num != 0 {
		remainder = num % n
		fmt.Println(remainder)

		remainder_string = tenToAny[remainder]
		new_num_str = remainder_string + new_num_str
		num = num / n
	}

	if len(new_num_str) < 8 {
		j := 8 - len(new_num_str)
		for i := 0; i < j; i++ {
			new_num_str = "0" + new_num_str
		}
	}

	return new_num_str
}
