Esempio n. 1
0
        public static decimal DecimalDecription(decimal value, string key)
        {
            //Random rnd = new Random();
            //decimal randomNumbers = rnd.Next(1, 99);

            string cipherInString = value.ToString();

            var enkriptedKey = RijndaelHelper.Encrypt(key, key);

            byte[] keyInBytes = Encoding.UTF8.GetBytes(enkriptedKey);

            decimal randomNumber = 0;

            for (int i = 0; i < keyInBytes.Length; i++)
            {
                randomNumber = (keyInBytes[i] * i) + randomNumber;
                randomNumber = (i * 255) + randomNumber;
            }

            string randomString = randomNumber.ToString();
            //for (int i = 0; i < randomNumbers; i++)
            //{
            //    randomNumber = randomNumber + (8 * i);
            //}

            int j = 0;

            var plainInString = "";

            for (int i = 0; i < cipherInString.Length; i++)
            {
                if (j >= randomString.Length)
                {
                    j = 0;
                }
                int indexof;
                int cipherstring = (int)Char.GetNumericValue(cipherInString[i]);    //cipher.Substring(i, 4);
                int keystring    = (int)Char.GetNumericValue(randomString[j]) >> 1; // randomString.Substring(j, 4);
                                                                                    //if (cipherstring == keystring)
                                                                                    //{
                                                                                    //    indexof = 0;
                                                                                    //}
                                                                                    //else
                                                                                    //{
                                                                                    //indexof = cipherstring ^ keystring;
                                                                                    //indexof = (indexof + 7 >= 10) ? (indexof - 7) * (-1) : indexof + 7;
                                                                                    //indexof = indexof*(-1);
                                                                                    //indexof = indexof + 7;
                                                                                    //}
                indexof = cipherstring ^ keystring;
                indexof = indexof - 1;
                indexof = indexof << 1;

                plainInString = plainInString + indexof;
                j++;
            }
            var noZeroStart = plainInString.TrimStart('0');

            return(Convert.ToDecimal(noZeroStart));
        }
Esempio n. 2
0
        public static decimal DecimalEncyption(decimal value, string key)
        {
            //Random rnd = new Random();
            //decimal randomNumbers = rnd.Next(1, 99);

            string valueInString = value.ToString();

            valueInString = valueInString.PadLeft(15, '0');

            var enkriptedKey = RijndaelHelper.Encrypt(key, key);

            byte[] keyInBytes = Encoding.UTF8.GetBytes(enkriptedKey);

            decimal randomNumber = 0;

            for (int i = 0; i < keyInBytes.Length; i++)
            {
                randomNumber = (keyInBytes[i] * i) + randomNumber;
                randomNumber = (i * 255) + randomNumber;
            }

            string randomString = randomNumber.ToString();
            //for (int i = 0; i < randomNumbers; i++)
            //{
            //    randomNumber = randomNumber + (8 * i);
            //}

            int j = 0;

            string cipherInString = "";

            for (int i = 0; i < valueInString.Length; i++)
            {
                if (j >= randomString.Length)
                {
                    j = 0;
                }
                int indexof;
                int plainstring = (int)Char.GetNumericValue(valueInString[i]);
                int keystring   = (int)Char.GetNumericValue(randomString[j]) >> 1;
                //if (plainstring == 0)
                //{
                //    indexof = keystring;
                //}
                //else
                //{
                //indexof = plainstring - 7;
                //indexof = (indexof < 0) ? indexof * (-1) : indexof;
                //indexof = indexof ^ keystring;

                //indexof = plainstring - 7;
                //indexof = indexof * (-1);
                //indexof = indexof ^ keystring;
                indexof = plainstring >> 1;
                indexof = indexof + 1;
                indexof = indexof ^ keystring;
                //}
                cipherInString = cipherInString + indexof;
                j++;
            }
            j = 0;
            //var plainInString = "";
            //for (int i = 0; i < cipherInString.Length; i++)
            //{
            //    if (j >= randomString.Length)
            //        j = 0;
            //    int indexof;
            //    int cipherstring = (int)Char.GetNumericValue(cipherInString[i]);//cipher.Substring(i, 4);
            //    int keystring = (int)Char.GetNumericValue(randomString[j]);// randomString.Substring(j, 4);
            //    if (cipherstring == keystring)
            //    {
            //        indexof = 0;
            //    }
            //    else
            //    {
            //        indexof = cipherstring ^ keystring;
            //        indexof = (indexof + 8 >= 10) ? (indexof - 8) * (-1) : indexof + 8;
            //    }
            //    plainInString = plainInString + indexof;
            //    j++;
            //}
            return(Convert.ToDecimal(cipherInString));
        }