コード例 #1
0
ファイル: En.cs プロジェクト: ParallelTestRunner/PTR
        public static string GetKey(string strFormat)
        {
            StringBuilder sbLockKey = new StringBuilder();
            int           iValue    = En.RandomNumberGenerator.Next(4, 9);
            int           k         = 0;

            while (0 != iValue)
            {
                k = En.RandomNumberGenerator.Next(11, 101);
                if (0 == k % 4)
                {
                    sbLockKey.Append(En.RandomNumberGenerator.Next(11, 101).ToString());
                }
                else if (0 == k % 3)
                {
                    sbLockKey.Append(En.RandomNumberGenerator.Next(101, 1100).ToString());
                }
                else
                {
                    sbLockKey.Append(En.RandomNumberGenerator.Next(1100, 11000).ToString());
                }

                iValue--;
            }
            sbLockKey.Append(En.SEP);

            sbLockKey.Append(strFormat);

            sbLockKey.Append(En.SEP);
            iValue = En.RandomNumberGenerator.Next(3, 6);
            k      = 0;
            while (0 != iValue)
            {
                k = En.RandomNumberGenerator.Next(11, 101);
                if (0 == k % 4)
                {
                    sbLockKey.Append(En.RandomNumberGenerator.Next(101, 1100).ToString());
                }
                else if (0 == k % 3)
                {
                    sbLockKey.Append(En.RandomNumberGenerator.Next(1100, 11000).ToString());
                }
                else
                {
                    sbLockKey.Append(En.RandomNumberGenerator.Next(11, 101).ToString());
                }

                iValue--;
            }
            strFormat = sbLockKey.ToString();

            char[]        charArray             = null;
            int           i                     = 0;
            List <string> strListSubNumericTime = new List <string>();
            int           iMinRandomDigit       = 2;
            int           iMaxRandomDigit       = 3;

            int iEnCharValue = 0;

            foreach (char ch in strFormat)
            {
                if (0 == i)
                {
                    charArray = new char[En.MAX_POS_DISTRIBUTION];
                }
                charArray[i] = ch;

                if (i == En.MAX_POS_DISTRIBUTION - 1)
                {
                    for (k = 0; k < En.MAX_POS_DISTRIBUTION; k++)
                    {
                        iEnCharValue  = System.Convert.ToInt32(charArray[En.PosSwap[k]]);
                        iEnCharValue += En.EN_VALUE1;
                        strListSubNumericTime.Add(iEnCharValue.ToString());
                        if (iMinRandomDigit > strListSubNumericTime[strListSubNumericTime.Count - 1].Length)
                        {
                            iMinRandomDigit = strListSubNumericTime[strListSubNumericTime.Count - 1].Length;
                        }
                        if (iMaxRandomDigit < strListSubNumericTime[strListSubNumericTime.Count - 1].Length)
                        {
                            iMaxRandomDigit = strListSubNumericTime[strListSubNumericTime.Count - 1].Length;
                        }
                    }
                    charArray = null;
                    i         = 0;
                }
                else
                {
                    i++;
                }
            }

            if (i > 0)
            {
                while (i > 0)
                {
                    iEnCharValue  = System.Convert.ToInt32(charArray[--i]);
                    iEnCharValue += En.EN_VALUE2;
                    strListSubNumericTime.Add(iEnCharValue.ToString());
                }
            }

            iMinRandomDigit = System.Convert.ToInt32(Math.Pow(10, iMinRandomDigit - 1));
            iMaxRandomDigit = System.Convert.ToInt32(Math.Pow(10, iMaxRandomDigit)) - 1;

            string strLastRandom    = "0";
            int    iLastRandomTotal = 0;
            int    m = 0;

            k = 0;
            int           PrimePosIndex           = 0;
            List <string> strListEnSubNumericTime = new List <string>();
            StringBuilder sbEnSubNumericTime      = new StringBuilder();

            for (i = 0; i < strListSubNumericTime.Count; i++)
            {
                iLastRandomTotal = 0;
                for (m = PrimePosIndex; m < En.PrimePos[k]; m++)
                {
                    strLastRandom = En.GetNextValue(strListSubNumericTime, 0 == m % 2, iMinRandomDigit, iMaxRandomDigit);
                    sbEnSubNumericTime.Append(strLastRandom);
                    sbEnSubNumericTime.Append(" ");
                }

                foreach (char ch in strLastRandom)
                {
                    iLastRandomTotal = (iLastRandomTotal * 10) + Int32.Parse(ch.ToString());
                }

                if (iLastRandomTotal != 299)
                {
                    iLastRandomTotal %= 299;
                    iLastRandomTotal  = (iLastRandomTotal >= 21) ? iLastRandomTotal : (iLastRandomTotal + 51);
                }

                iLastRandomTotal += Int32.Parse(strListSubNumericTime[i]);

                sbEnSubNumericTime.Append(iLastRandomTotal.ToString());
                sbEnSubNumericTime.Append(" ");

                PrimePosIndex = PrimePos[k] + 1;
                k++;
                if (k == En.MAX_POS_DISTRIBUTION)
                {
                    sbEnSubNumericTime.Append(En.GetNextValue(strListSubNumericTime, false, iMinRandomDigit, iMaxRandomDigit));
                    sbEnSubNumericTime.Append(" ");

                    strListEnSubNumericTime.Add(sbEnSubNumericTime.ToString());
                    k             = 0;
                    PrimePosIndex = 0;
                    sbEnSubNumericTime.Remove(0, sbEnSubNumericTime.Length);
                }
            }

            if (k > 0)
            {
                strListEnSubNumericTime.Add(sbEnSubNumericTime.ToString());
                sbEnSubNumericTime.Remove(0, sbEnSubNumericTime.Length);
            }

            for (i = 0; i < strListEnSubNumericTime.Count; i++)
            {
                sbEnSubNumericTime.Append(strListEnSubNumericTime[i]);
            }

            sbEnSubNumericTime.Remove(sbEnSubNumericTime.Length - 1, 1);

            strFormat = sbEnSubNumericTime.ToString();
            i         = 0;
            char charReplace;

            foreach (char ch in strFormat)
            {
                if (ch != ' ')
                {
                    iEnCharValue = Int32.Parse(ch.ToString());
                    charReplace  = En.charReplaceArray[iEnCharValue];
                    sbEnSubNumericTime.Replace(ch, charReplace, i, 1);
                }
                i++;
            }

            return(sbEnSubNumericTime.ToString());
        }
コード例 #2
0
ファイル: En.cs プロジェクト: ParallelTestRunner/PTR
        public static string GetLicenseInfo(string strTime, string strFormat)
        {
            char          charReplace;
            StringBuilder sbCharReplace = new StringBuilder();

            string        strLastRandom         = "0";
            int           iLastRandomTotal      = 0;
            List <string> strListSubNumericTime = new List <string>();

            string[] strArrayEnSubNumericTime = strFormat.Split();
            int      iStartingIndex           = 0;
            int      k = 0;
            int      i = En.PrimePos[k];

            while ((i + iStartingIndex) < strArrayEnSubNumericTime.Length)
            {
                strTime = strArrayEnSubNumericTime[i + iStartingIndex];
                foreach (char ch in strTime)
                {
                    charReplace = ch;
                    En.charReplaceF(ref charReplace);
                    sbCharReplace.Append(charReplace);
                }

                iLastRandomTotal = 0;
                strLastRandom    = strArrayEnSubNumericTime[i + iStartingIndex - 1];
                foreach (char ch in strLastRandom)
                {
                    charReplace = ch;
                    En.charReplaceF(ref charReplace);
                    iLastRandomTotal = (iLastRandomTotal * 10) + Int32.Parse(charReplace.ToString());
                }

                if (iLastRandomTotal != 299)
                {
                    iLastRandomTotal %= 299;
                    iLastRandomTotal  = (iLastRandomTotal >= 21) ? iLastRandomTotal : (iLastRandomTotal + 51);
                }

                iLastRandomTotal = (Int32.Parse(sbCharReplace.ToString())) - iLastRandomTotal;

                strListSubNumericTime.Add(iLastRandomTotal.ToString());
                sbCharReplace.Remove(0, sbCharReplace.Length);

                if (i == En.PrimePos[En.PrimePos.Length - 1])
                {
                    k = 0;
                    iStartingIndex += En.PrimePos[En.PrimePos.Length - 1] + 2;
                }
                else
                {
                    k++;
                }
                i = En.PrimePos[k];
            }

            i = 0;
            iStartingIndex = 0;
            char[] strArrOrderedSubNumericTime = new char[strListSubNumericTime.Count];
            while (i < strListSubNumericTime.Count)
            {
                if (strListSubNumericTime.Count - iStartingIndex < En.PosSwap.Length)
                {
                    break;
                }

                k  = Int32.Parse(strListSubNumericTime[i]);
                k -= En.EN_VALUE1;
                strArrOrderedSubNumericTime[iStartingIndex + En.PosSwap[i - iStartingIndex]] = System.Convert.ToChar(k);

                if ((i - iStartingIndex) == (En.PosSwap.Length - 1))
                {
                    iStartingIndex += PosSwap.Length;
                }
                i++;
            }

            if (strListSubNumericTime.Count - iStartingIndex < En.PosSwap.Length)
            {
                int m = i;
                k = strListSubNumericTime.Count - 1;
                while (k >= i)
                {
                    iStartingIndex  = Int32.Parse(strListSubNumericTime[k--]);
                    iStartingIndex -= En.EN_VALUE2;
                    strArrOrderedSubNumericTime[m++] = System.Convert.ToChar(iStartingIndex);
                }
            }

            StringBuilder sbTime = new StringBuilder();

            for (i = 0; i < strArrOrderedSubNumericTime.Length; i++)
            {
                sbTime.Append(strArrOrderedSubNumericTime[i]);
            }

            strTime = sbTime.ToString();

            strTime = strTime.Substring(strTime.IndexOf(En.SEP) + En.SEP.Length);
            strTime = strTime.Substring(0, strTime.LastIndexOf(En.SEP));

            return(strTime);
        }
コード例 #3
0
        public bool DoesThisMachineHaveAValidLicense()
        {
            if (_bGiveFreeLicense)
            {
                return(true);
            }

            if (!System.IO.File.Exists(LockFile))
            {
                StringBuilder sbLock = new StringBuilder(GetHardDriveSerialKey());
                sbLock.Append(En.SEP);
                sbLock.Append(GetMacAddress());
                string strLock = En.GetKey(sbLock.ToString());
                using (System.IO.FileStream FileStream = System.IO.File.Open(LockFile, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
                {
                    System.IO.StreamWriter StreamWriter = new System.IO.StreamWriter(FileStream);
                    StreamWriter.WriteLine(strLock);
                    StreamWriter.Flush();
                    FileStream.Flush();
                }
            }

            if (!System.IO.File.Exists(KeyFile))
            {
                StringBuilder sbKey = new StringBuilder(GetHardDriveSerialKey());
                sbKey.Append(En.SEP);
                sbKey.Append(GetMacAddress());
                string strKey = En.GetKey(sbKey.ToString());
                using (System.IO.FileStream FileStream = System.IO.File.Open(KeyFile, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
                {
                    System.IO.StreamWriter StreamWriter = new System.IO.StreamWriter(FileStream);
                    StreamWriter.WriteLine(strKey);
                    StreamWriter.WriteLine(@"ik 4Ak 1a 4ak ssA s11 1a ss7 is kN 1a 40A A7i 0iN is Nas 41a i77 ik 71s i0 iN i1 ssi i0 ssA is si4 4s4 k17 i4 417 i7 7Ai Na sAA iN ssi i0 ka4 sai N4 sA7 A71 ii 0N4 s7i 71k 7a Ais is 1a4 is sai ssA skA i4 k17 444 7is i7 ii7 i1 sis is ssa 1a ssi 1s 1i0 i0 40i Ai7 7ks is 07s sas 4A7 ii 4ki ik 04s i4 sa0 i7 ss4 7a 71i 441 ks1 i0 004 iA ka1 i7 sa0 i7 sss saA kk1 ss4 ss s4a Nss i7 Nk0 AA4 70a ik 4k 1a k4k i7 sak Na sN0 is i4s 4kA 4A7 1a s4k kN AAk ia sa1 7a 0s 7a 0s ia 7i0 4k4 NAk Na sik 4Ns ksN s47 AsA iA 0Ni i1 01 1a s1i i7 sA0 474 1AA ii kN7 ss4 0aA saA siA ss4 s1A ss4 477 i0 11a ssA k1N i0 iN0 7aA k0a sai 1NA ik NN7 i4 sa7 1a ss4 i1 i4 sAa sk i1 AaN 1s 74A ss4 sks is sa4 saA iN7 i1 ANa ss1 704 1a iis Aa4 NNa is kis is 4AN saA sii i7 sa1 sai ANN s74 1A0 is i44 ik Ass iA sa7 7a 0s ii 0ia i0 NsN 4ks kk1 is 1a7 ssN isk is ikN 1a s1a i4 ssA 1a 0i ia sak siN 4a4 sa0 Nas is s7A is si7 iA s14 iA AN0 i1 siA 4a7 11k i4 0aa s44 011 iA NA0 i1 1kN i4 sk1 i7 07 ik kkA 4ii NA0 ik 47A i7 1iN is s40 iA siN i4 1ss iA 14i Ni AAa i7 ia0 411 7a1 i7 i4N i7 i1k iN sks i4 saN saA 0A1 sis Nia 1s 1ss i4 As0 iA saN is sa1 is sak i4 7s0 sk4 01s i4 N00 ss4 4sa iA ksa is 7is is sai Na sAs is iNa AAi Aa4 1a 774 is si0 iA saN 1a ss4 i1 s0A ik si s4i A04 i1 i1 ss1 si7 saA 4as i4 1iA iN sa0 i1 ssA 1a i7k Aai i1A");
                    StreamWriter.Flush();
                    FileStream.Flush();
                }
            }

            System.IO.TextReader TextReader = new System.IO.StreamReader(KeyFile);

            string strKeyInfo       = TextReader.ReadLine();
            string strDecryptedLock = En.GetLicenseInfo("", strKeyInfo);
            int    iIndex           = 0;
            string strHSDN          = strDecryptedLock.Substring(iIndex, strDecryptedLock.IndexOf(En.SEP, iIndex) - iIndex);

            iIndex += strHSDN.Length;
            iIndex += En.SEP.Length;
            string strMANIC = strDecryptedLock.Substring(iIndex);

            var time1 = InternetTime.GetInternetTime();
            var time2 = DateTime.Parse(En.GetLicenseInfo("", TextReader.ReadLine()));

            if (time1 <= time2)
            {
                int iDaysLeft = (int)(time2 - time1).TotalDays;
                if (iDaysLeft <= 15)
                {
                    Console.Write("Your license will expire after " + iDaysLeft + " days.");
                    Console.WriteLine();
                    System.Threading.Thread.Sleep(2000);
                }
                return(true);
            }

            return(false);
        }