using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;

namespace License
{
    static class LicenseKey
    {
        static void Main()
        {
            string key = GenerateKey("5D67D8FF", 81561930, 30);
            Console.WriteLine(key);
        }

        static string GenerateKey(string secretPhase, int machineCode, int days, bool unlimited = false)
        {
            secretPhase = twentyfiveByteHash(ComputeMD5(secretPhase));

            int value = Convert.ToInt32(DateTime.Today.ToString("yyMMdd"));
            decimal d = 0m + value;
            d *= 1000m;
            d += days;
            d *= 1000m;
            bool[] _tfg = new bool[8];
            _tfg[0] = unlimited;
            d += booleanToInt(_tfg);
            d *= 100000000m;
            d += machineCode;

            int hash = getEightByteHash(d.ToString());
            string text = hash + encText(d.ToString(), secretPhase);
            text = base10ToBase26(text);

            string key = string.Concat(new string[] { text.Substring(0, 5), "-", text.Substring(5, 5), "-", text.Substring(10, 5), "-", text.Substring(15, 5) });
            return key;
        }

        static string ComputeMD5(string text)
        {
            StringBuilder stringBuilder = new StringBuilder();
            MD5 md = MD5.Create();
            byte[] array = md.ComputeHash(Encoding.Unicode.GetBytes(text));
            md.Clear();
            for (int i = 0; i < array.Length; i++)
            {
                stringBuilder.Append(((int)(byte.MaxValue - array[i])).ToString("X2"));
            }
            return stringBuilder.ToString();
        }


        static string twentyfiveByteHash(string s)
        {
            int num = s.Length / 5;
            string[] array = new string[num + 1];
            if (s.Length <= 5)
            {
                array[0] = getEightByteHash(s).ToString();
            }
            else if (s.Length > 5)
            {
                for (int i = 0; i <= num - 2; i++)
                {
                    array[i] = getEightByteHash(s.Substring(i * 5, 5)).ToString();
                }
                array[array.Length - 2] = getEightByteHash(s.Substring((array.Length - 2) * 5, s.Length - (array.Length - 2) * 5)).ToString();
            }
            return string.Join("", array);
        }
        static string decText(string _encryptedPhase, string _secretPhase)
        {
            string text = "";
            for (int i = 0; i <= _encryptedPhase.Length - 1; i++)
            {
                text += modulo(Convert.ToInt32(_encryptedPhase.Substring(i, 1)) - Convert.ToInt32(_secretPhase.Substring(modulo(i, _secretPhase.Length), 1)), 10);
            }
            return text;
        }
        static string decrypt(string _key, string _secretPhase)
        {
            string result;
            if (string.IsNullOrEmpty(_secretPhase) | _secretPhase == null)
            {
                result = base26ToBase10(_key);
            }
            else
            {
                string text = base26ToBase10(_key);
                result = text.Substring(0, 8) + decText(text.Substring(8), _secretPhase);
            }
            return result;
        }

        static string base26ToBase10(string s)
        {
            string text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            BigInteger left = default(BigInteger);
            for (int i = 0; i <= s.Length - 1; i++)
            {
                BigInteger right = powof(26, s.Length - i - 1);
                left += text.IndexOf(s.Substring(i, 1)) * right;
            }
            return left.ToString();
        }

        static BigInteger powof(int x, int y)
        {
            BigInteger bigInteger = 1;
            BigInteger result;
            if (y == 0)
            {
                result = 1;
            }
            else if (y == 1)
            {
                result = x;
            }
            else
            {
                for (int i = 0; i <= y - 1; i++)
                {
                    bigInteger *= x;
                }
                result = bigInteger;
            }
            return result;
        }

        static int booleanToInt(bool[] _booleanArray)
        {
            int num = 0;
            for (int i = 0; i < _booleanArray.Length; i++)
            {
                bool flag = _booleanArray[i];
                if (flag)
                {
                    num += Convert.ToInt32(Math.Pow(2.0, (double)(_booleanArray.Length - i - 1)));
                }
            }
            return num;
        }
        static int modulo(int _num, int _base)
        {
            return _num - _base * Convert.ToInt32(Math.Floor((double)_num / _base));
        }
        static string encText(string _inputPhase, string _secretPhase)
        {
            //_inputPhase.Dump();
            string text = "";
            for (int i = 0; i <= _inputPhase.Length - 1; i++)
            {
                text += modulo(Convert.ToInt32(_inputPhase.Substring(i, 1)) + Convert.ToInt32(_secretPhase.Substring(modulo(i, _secretPhase.Length), 1)), 10);
            }
            return text;
        }
        static string base10ToBase26(string s)
        {
            char[] array = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
            BigInteger num = BigInteger.Parse(s);
            char[] array2 = new char[s.ToString().Length + 1];
            int num2 = 0;
            while (num >= 26)
            {
                int num3 = (int)(num % 26);
                array2[num2] = array[num3];
                num = (num - num3) / 26;
                num2++;
            }
            array2[num2] = array[(int)(num)];
            string text = "";
            for (int i = num2; i >= 0; i--)
            {
                text += array2[i];
            }
            return text;
        }


        static string Return_Lenght(string Number, int Lenght)
        {
            if (Number.ToString().Length != Lenght)
            {
                while (Number.ToString().Length != Lenght)
                {
                    Number = "0" + Number;
                }
            }
            return Number;
        }
        static bool[] intToBoolean(int _num)
        {
            string text = Return_Lenght(Convert.ToInt32(Convert.ToString(_num, 2)).ToString(), 8);
            bool[] array = new bool[8];
            for (int i = 0; i <= 7; i++)
            {
                array[i] = ((text.ToString().Substring(i, 1) == "1") ? true : false);
            }
            return array;
        }
        static int getEightByteHash(string s, int MUST_BE_LESS_THAN = 100000000)
        {
            uint num = 0U;
            foreach (byte b in Encoding.Unicode.GetBytes(s))
            {
                num += (uint)b;
                num += num << 10;
                num ^= num >> 6;
            }
            num += num << 3;
            num ^= num >> 11;
            num += num << 15;
            int num2 = (int)((ulong)num % (ulong)((long)MUST_BE_LESS_THAN));
            int num3 = MUST_BE_LESS_THAN / num2;
            if (num3 > 1)
            {
                num2 *= num3;
            }
            return num2;
        }

        public static int getEightByteHash2(string s)
        {
            //This function generates a eight byte hash

            //The length of the result might be changed to any length
            //just set the amount of zeroes in MUST_BE_LESS_THAN
            //to any length you want
            uint hash = 0;

            int MUST_BE_LESS_THAN = 100000000;//1000000;

            foreach (byte b in System.Text.Encoding.Unicode.GetBytes(s))
            {
                hash += b;
                hash += (hash << 10);
                hash ^= (hash >> 6);
            }

            hash += (hash << 3);
            hash ^= (hash >> 11);
            hash += (hash << 15);

            int result = (int)(hash % MUST_BE_LESS_THAN);

            //we want the result to not be zero, as this would thrown an exception in check.
            if (result == 0)
                result = 1;


            int check = MUST_BE_LESS_THAN / result;

            if (check > 1)
            {
                result *= check;
            }

            //when result is less than MUST_BE_LESS_THAN, multiplication of result with check will be in that boundary.
            //otherwise, we have to divide by 10.
            if (MUST_BE_LESS_THAN == result)
                result /= 10;


            return result;
        }
        // Define other methods and classes here
    }
}
 
by

C Sharp Online Compiler

Write, Run & Share C# code online using OneCompiler's C# online compiler for free. It's one of the robust, feature-rich online compilers for C# language, running on the latest version 8.0. Getting started with the OneCompiler's C# compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C# and start coding.

Read inputs from stdin

OneCompiler's C# online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.

using System;
 
namespace Sample
{
  class Test
    {
      public static void Main(string[] args)
       {
         string name;
         name = Console.ReadLine();
         Console.WriteLine("Hello {0} ", name);
	}
     }
}

About C Sharp

C# is a general purpose object-oriented programming language by Microsoft. Though initially it was developed as part of .net but later it was approved by ECMA and ISO standards.

You can use C# to create variety of applications, like web, windows, mobile, console applications and much more using Visual studio.

Syntax help

Data types

Data TypeDescriptionRangesize
intTo store integers-2,147,483,648 to 2,147,483,6474 bytes
doubleto store large floating point numbers with decimalscan store 15 decimal digits8 bytes
floatto store floating point numbers with decimalscan store upto 7 decimal digits4 bytes
charto store single characters-2 bytes
stringto stores text-2 bytes per character
boolto stores either true or false-1 bit

Variables

Syntax

datatype variable-name = value;

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition or set of few conditions IF-ELSE is used.

if(conditional-expression) {
   // code
} 
else {
   // code
}

You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to If-Else-If ladder.

switch(conditional-expression) {    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
...    
    
default:     
 // code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement) {
  // code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while(condition) {
 // code 
}

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {
  // code 
} while (condition);

Arrays

Array is a collection of similar data which is stored in continuous memory addresses. Array values can be fetched using index. Index starts from 0 to size-1.

Syntax

data-type[] array-name;

Methods

Method is a set of statements which gets executed only when they are called. Call the method name in the main function to execute the method.

Syntax

static void method-name() 
{
  // code to be executed
}