예제 #1
0
        public static string Convert(
            string input,
            BaseCharSet sourceAlphabet,
            BaseCharSet targetAlphabet)
        {
            string sourceCharset = GetCharsetOf(sourceAlphabet);
            string targetCharset = GetCharsetOf(targetAlphabet);
            var    number        = ToDec(sourceCharset, input);
            var    targetString  = ToBase(targetCharset, number);

            return(targetString);
        }
예제 #2
0
        private static string GetCharsetOf(BaseCharSet baseCharSet)
        {
            string charset = "";

            switch (baseCharSet)
            {
            case BaseCharSet.Base10:
                charset = CHARSET_Base10;
                break;

            case BaseCharSet.Base16:
                charset = CHARSET_Base16;
                break;

            case BaseCharSet.Base32_CustomV1:
                charset = CHARSET_Base32_CustomV1;
                break;

            case BaseCharSet.Base36:
                charset = CHARSET_Base36;
                break;

            case BaseCharSet.Base36_Custom:
                charset = CHARSET_Base36_Custom;
                break;

            case BaseCharSet.Base62:
                charset = CHARSET_Base62;
                break;

            case BaseCharSet.Base64:
                charset = BASE64_RFC4648;
                break;

            case BaseCharSet.Base64_Safe:
                charset = BASE64_RFC4648_SAFE;
                break;

            case BaseCharSet.Base66_Url_Safe_Custom:
                charset = CHARSET_Base66_URL_SAFE_Custom;
                break;

            case BaseCharSet.Base66_Url_Safe:
                charset = CHARSET_Base66_URL_SAFE;
                break;

            case BaseCharSet.Base85:
                charset = CHARSET_Base85;
                break;

            case BaseCharSet.Base95:
                charset = CHARSET_Base95;
                break;

            case BaseCharSet.Base94_Custom:
                charset = CHARSET_Base94_Custom;
                break;

            case BaseCharSet.Base32_CustomV2:
                charset = CHARSET_Base32_CustomV2;
                break;
            }

            return(charset);
        }
예제 #3
0
        /// <summary>
        ///     Converts an input string in base-n into the equivalent in base-ten based on the given charset
        /// </summary>
        /// <param name="input"></param>
        /// <param name="base"></param>
        /// <param name="charset"></param>
        /// <returns>BigInteger base-ten value of given input</returns>
        public static BigInteger ToDec(string input, BaseCharSet @base)
        {
            var basedCharset = GetCharsetOf(@base);

            return(ToDec(basedCharset, input));
        }
예제 #4
0
        public static string ToBase(BigInteger input, BaseCharSet targetBase)
        {
            string charset = GetCharsetOf(targetBase);

            return(ToBase(charset, input));
        }