/// <summary> /// 10进制转换为62进制【混淆】 /// </summary> /// <param name="num"></param> /// <returns></returns> public string ConfusionConvert(long num) { if (num.ToString().Length > MaxLength) { throw new Exception($"转换值不能超过最大位数{MaxLength}"); } var n = num.ToString() .PadLeft(MaxLength, '0') .ToCharArray() .Reverse(); return(Convert(long.Parse(string.Join("", n))).PadLeft(CodeLength, SeqKey.First())); }
/// <summary> /// 将62进制转为10进制【简单】 /// </summary> /// <param name="num"></param> /// <returns></returns> private long Convert(string num) { long v = 0; int Len = num.Length; for (int i = Len - 1; i >= 0; i--) { int t = SeqKey.IndexOf(num[i]); double s = (Len - i) - 1; long m = (long)(Math.Pow(62, s) * t); v += m; } return(v); }