Beispiel #1
0
        public static long SC()
        {
            string sc = "";

            sc += showMac();

            string a = FillCharacter(SystemInfo.RunQuery("Processor", "ProcessorId"), 3);
            string b = FillCharacter(SystemInfo.RunQuery("BaseBoard", "Product"), 3);

            sc += a + b;
            long code = 0;

            Radix.Decode(sc, 0x24L, ref code);
            return(code);
        }
Beispiel #2
0
    private static string ProcessExpression(string expression, long radix)
    {
        char[] separators = { '(', ')', '+', '-', '*', '/', '%', '\\', '^', '!' };

        ArrayList processed_parts = new ArrayList();

        string[] parts = expression.Split(separators, StringSplitOptions.RemoveEmptyEntries);
        foreach (string part in parts)
        {
            bool in_math_library = s_math_library[part.ToUpper()] != null;
            if (!processed_parts.Contains(part))
            {
                // 1. consruct Math.Xxx() functions and Math.XXX constants
                if (in_math_library)
                {
                    expression = expression.Replace(part, "Math." + s_math_library[part.ToUpper()]);
                }
                // 2. decode to base-10
                else
                {
                    try
                    {
                        expression = expression.Replace(part, Radix.Decode(part, radix).ToString());
                    }
                    catch
                    {
                        continue; // leave part as is
                    }
                }
            }
            processed_parts.Add(part); // so we don't replace it again
        }

        // Only allow small letters as constant and reserve capital letters for higher base systems
        // SPECIAL CASES: PI
        expression = expression.Replace("pi", "Math.PI");
        // SPECIAL CASE: Euler's Constant
        expression = expression.Replace("e", "Math.E");
        // SPECIAL CASE: Golden ratio
        expression = expression.Replace("phi", "1.61803398874989");
        // SPECIAL CASE: ^ power operator
        parts = expression.Split('^');
        // process simple case for now.
        if (parts.Length == 2)
        {
            double n1 = 0.0D;
            try
            {
                n1 = double.Parse(parts[0]);
            }
            catch
            {
                if (parts[0] == "e")
                {
                    n1 = Math.E;
                }
                else if (parts[0] == "pi")
                {
                    n1 = Math.PI;
                }
                else if (parts[0] == "phi")
                {
                    n1 = 1.61803398874989D;
                }
                else if (parts[0] == "Math.E")
                {
                    n1 = Math.E;
                }
                else if (parts[0] == "Math.PI")
                {
                    n1 = Math.PI;
                }
            }

            double n2 = 0.0D;
            try
            {
                n2 = double.Parse(parts[1]);
            }
            catch
            {
                if (parts[1] == "e")
                {
                    n2 = Math.E;
                }
                else if (parts[1] == "pi")
                {
                    n2 = Math.PI;
                }
                else if (parts[1] == "phi")
                {
                    n2 = 1.61803398874989D;
                }
                else if (parts[1] == "Math.E")
                {
                    n2 = Math.E;
                }
                else if (parts[1] == "Math.PI")
                {
                    n2 = Math.PI;
                }
            }

            expression = "Math.Pow(" + n1 + "," + n2 + ")";
        }
        // SPECIAL CASE: ! Factorial
        parts = expression.Split('!');
        // process simple case for now.
        if (parts.Length == 2)
        {
            long n         = long.Parse(parts[0]);
            long factorial = 1L;
            for (long i = 1; i <= n; i++)
            {
                factorial *= i;
            }
            expression = factorial.ToString();
        }
        // SPECIAL CASE: double and int division
        expression = expression.Replace("/", "/(double)");
        expression = expression.Replace("\\", "/");

        return(expression);
    }
Beispiel #3
0
    public static void Test(string[] args)
    {
        string s = null;
        long   l = 0L;
        double d = 0.0D;

        // run once with symbolic_displaybolic notation false
        // and once with symbolic_displaybolic notation true
        for (int tr = 0; tr < 2; tr++)
        {
            bool symbolic_display = (tr == 1);

            // TEST RUN
            Console.WriteLine("TEST: First 10000 integers in base 2 to 36");
            Console.WriteLine(DateTime.Now.ToString("mm:ss:fff"));
            for (long i = 0L; i < 10000L; i++)
            {
                for (int r = 2; r <= 36; r++)
                {
                    s = Radix.Encode(i, r, symbolic_display);
                    l = Radix.Decode(s, r, symbolic_display);
                    if (i != l)
                    {
                        Console.WriteLine("error: r i l {0} {1} {2}", r, i, l);
                    }
                    d = Radix.Decode(s, r, symbolic_display);
                    if (d != i)
                    {
                        Console.WriteLine("error: r, l d {0} {1} {2}", r, l, d);
                    }
                }
            }
            Console.WriteLine(DateTime.Now.ToString("mm:ss:fff"));
            Console.WriteLine();

            Console.WriteLine("TESTRUN 2: two well known doubles in base 2 to 36");
            Console.ReadLine();
            Console.WriteLine("\n PI \n");
            for (int r = 2; r <= 36; r++)
            {
                s = Radix.Encode(Math.PI, r, symbolic_display);
                d = Radix.Decode(s, r, symbolic_display);
                if (Math.PI != d)
                {
                    Console.WriteLine("error: radix {0} : {1}  {2}", r, d, Math.PI);
                }
            }

            Console.WriteLine("\n  E \n");
            for (int r = 2; r <= 36; r++)
            {
                s = Radix.Encode(Math.E, r, symbolic_display);
                d = Radix.Decode(s, r, symbolic_display);
                if (Math.E != d)
                {
                    Console.WriteLine("error: radix {0} : {1}  {2}", r, d, Math.E);
                }
            }
            Console.WriteLine();

            Console.WriteLine("TESTRUN 3: force an error while decoding");
            Console.ReadLine();
            try
            {
                l = Radix.Decode("C000", 7, symbolic_display);
                Console.WriteLine("{0}", l);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine();
            }
        }

        Console.WriteLine("TESTRUN 4: some usage");

        s = Radix.Encode(100, 4, true);
        Console.WriteLine(s);
        l = Radix.Decode(s, 4, true);
        Console.WriteLine(l);
        s = Radix.Encode(100, 16);
        Console.WriteLine(s);
        Console.WriteLine();
        s = Radix.Encode(1000000000000, 11);
        Console.WriteLine(s);
        Console.WriteLine(Radix.Spaces(s, 2, '.'));
        Console.WriteLine(Radix.Spaces(s, 4, '.'));
        Console.WriteLine(Radix.Spaces(s, 4));
        Console.WriteLine();

        Console.WriteLine("Convert a hexadecimal IP address");
        l = Radix.Decode("C0FFCCBB", 16);
        s = Radix.Encode(l, 256, true);
        Console.WriteLine(s);
        l = Radix.Decode(s, 256, true);
        Console.WriteLine(l.ToString());
        s = Radix.Encode(l, 16);
        Console.WriteLine(s);

        Console.WriteLine();

        for (int i = 0; i <= 100; i++)
        {
            Console.Write(Radix.Encode(i, 13) + " ");
        }

        Console.WriteLine();
        Console.WriteLine("ready");
    }
Beispiel #4
0
        public static bool Parse(string act, string reg)
        {
            Version version = Version.Demo;

            if (reg.Length != 29)
            {
                Alert.Show("Mã đăng kí không đúng !", Color.Red);
                version = Version.Demo;
                return(false);
            }

            string x    = Backward(reg.ToUpper());
            long   num3 = 0;
            long   num4 = 0;
            long   num2 = 0;

            char[] trimChars = new char[] { '0' };
            string str       = x.Substring(0, 5);

            if (!isMACValid(str))
            {
                Alert.Show("Mã đăng kí không đúng !", Color.Red);
                version = Version.Demo;
                return(false);
            }
            string aaa = x.Substring(5, 6);
            string a   = Sc.FillCharacter(SystemInfo.RunQuery("Processor", "ProcessorId"), 3);
            string b   = Sc.FillCharacter(SystemInfo.RunQuery("BaseBoard", "Product"), 3);

            if (aaa != a + b)
            {
                Alert.Show("Mã đăng kí không đúng !", Color.Red);
                version = Version.Demo;
                return(false);
            }
            Radix.Decode(x.Substring(11, 6).TrimStart(trimChars), 0x24L, ref num3);
            long gUIDValue = GetGUIDValue(act.Replace("-", "").Replace(" ", "").ToUpper());

            if (num3 != gUIDValue)
            {
                Alert.Show("Mã đăng kí không đúng !", Color.Red);
                version = Version.Demo;
                return(false);
            }
            Radix.Decode(x.Substring(17, 6).TrimStart(trimChars), 0x24L, ref num4);
            StaticClass.m_Version = (int)num4;
            if ((StaticClass.m_Version & 0x88) == 0x88)
            {
                version = Version.Pro;
            }
            else if ((StaticClass.m_Version & 0x888) == 0x888)
            {
                version = Version.Enterprise;
            }
            else
            {
                version = Version.Demo;
            }
            Radix.Decode(x.Substring(23, 6).TrimStart(trimChars), 0x24L, ref num2);
            DateTime time = DateTime.FromOADate((double)num2);

            if ((DateTime.Compare(DateTime.Today, time) > 0))
            {
                Alert.Show("License hết hạn !", Color.Red);
                version = Version.Demo;
                return(false);
            }
            StaticClass.version = version;
            return(true);
        }
Beispiel #5
0
        public long CalculateValue(string text)
        {
            if (String.IsNullOrEmpty(text))
            {
                return(0L);
            }
            if (letter_values == null)
            {
                return(0L);
            }

            if (!text.IsArabic())  // eg English
            {
                text = text.ToUpper();
            }

            // simplify all text_modes
            text = text.SimplifyTo(text_mode);

            long result = 0L;

            if (letter_value.StartsWith("Base"))
            {
                string radix_str = "";
                int    pos       = 4;
                while (Char.IsDigit(letter_value[pos]))
                {
                    radix_str += letter_value[pos];
                    pos++;
                }
                int radix;
                if (int.TryParse(radix_str, out radix))
                {
                    StringBuilder str   = new StringBuilder();
                    string[]      words = text.Split();
                    foreach (string word in words)
                    {
                        for (int i = 0; i < word.Length; i++)
                        {
                            if (letter_values.ContainsKey(word[i]))
                            {
                                str.Insert(0, letter_values[word[i]]);
                            }
                        }
                        result    += Radix.Decode(str.ToString(), radix);
                        str.Length = 0;
                    }
                }
            }
            else
            {
                for (int i = 0; i < text.Length; i++)
                {
                    if (letter_values.ContainsKey(text[i]))
                    {
                        result += letter_values[text[i]];
                    }
                }
            }
            return(result);
        }