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

namespace aes
{
    internal class Program
    {
        static string Key = "b42e5+YWwQ6Yv/x2usUC3y7W67j/JtFsPYIrM+a8c3s=";
        static Dictionary<string, string[]> cryptText = new Dictionary<string, string[]>();
        static Dictionary<string, string[]> IV = new Dictionary<string, string[]>();
        static string[] dd = { "Saturnus", "Thunor", "Týr", "Máni", "Wōden", "Frigg", "Sól" };

        static void Init()
        {
            InitSaturnus();
            InitThunor();
            InitTýr();
            InitMáni();
            InitWōden();
            InitFrigg();
            InitSól();
        }

        static void InitSaturnus()
        {
            var cryptTextList = new List<string>() {
                "U2FsdGVkX1+1O+ZmIgttJH8=",
                "U2FsdGVkX1+SrIZIFMDVW2E=",
                "U2FsdGVkX18JRzfoygn2Y20=",
                "U2FsdGVkX18GDhU6ud+3DcQ=",
                "U2FsdGVkX1/n51zyK28c4GI=",
                "U2FsdGVkX18ugDFDV5lkglE="
            };

            cryptText.Add(dd[0], cryptTextList.ToArray());
            var IVList = new List<string>()
            {
                "xZAdKng0U5d82Np4PZsPww==",
                "YHVny/woeNDh9DpM94BBOQ==",
                "Muf/Frv5oLFRt6SyAiA6rQ==",
                "ehr7Twl2OF1fIJBKPbmcMA==",
                "lbc3yR4IWHSuZdbib3QdiA==",
                "b2Hi5VfTA6Q6Rsz2zHAvuA=="
            };
            IV.Add(dd[0], IVList.ToArray());
        }

        static void InitThunor()
        {
            var cryptTextList = new List<string>() {
                "U2FsdGVkX19rsWv2JfYRRb0=",
                "U2FsdGVkX1+4rdZjmR3tgko=",
                "U2FsdGVkX18ocJyAnLuozNE=",
                "U2FsdGVkX1/AOyr4suOc4MQ=",
                "U2FsdGVkX1+jD8DWwqTE910=",
                "U2FsdGVkX1/+ncfXosXHwKY="
            };
            cryptText.Add(dd[1], cryptTextList.ToArray());
            var IVList = new List<string>()
            {
                "MBc4iLpcZDrfSjeqJJmLEA==",
                "fKwuELhrHqQBeaIi2R+b8A==",
                "lHr6MzT0fYzqArra4GYm+g==",
                "AZkW78OLribXIy+ApGJQgA==",
                "WUxVtwiogwBgphfgHKwDzA==",
                "zoDZNgmPTlEjZdXdpBM8tA=="
            };
            IV.Add(dd[1], IVList.ToArray());
        }

        static void InitTýr()
        {
            var cryptTextList = new List<string>() {
                "U2FsdGVkX1/4DZqbUtYRZx8=",
                "U2FsdGVkX19czPjq8+/8UsE=",
                "U2FsdGVkX1/6ZfI36gjoLA8=",
                "U2FsdGVkX18V5valcsk1CsQ=",
                "U2FsdGVkX1+xG6R0mlCkPTE=",
                "U2FsdGVkX18g2+TuT4brgOk="
            };
            cryptText.Add(dd[2], cryptTextList.ToArray());
            var IVList = new List<string>()
            {
                "m0L/fmD3/jbh0AqJk71ehg==",
                "NnBKYEFiiAHdovEgMw7bNg==",
                "n+/VrL4x4OrWjJGVfDUSsw==",
                "70x6io7OfXVBss8yP1D1tg==",
                "VzBgGklGo66w7QEAZa0GAw==",
                "sDwVmAR6JW/kEstlwZUdZg=="
            };
            IV.Add(dd[2], IVList.ToArray());
        }

        static void InitMáni()
        {
            var cryptTextList = new List<string>() {
                "U2FsdGVkX19H6fCgY8RPxSQ=",
                "U2FsdGVkX1968V7WtkgBfrU=",
                "U2FsdGVkX1/8j4E7M4sVoog=",
                "U2FsdGVkX1/f6pEN6sJBUvQ=",
                "U2FsdGVkX1/gG/GRZhjmwYs=",
                "U2FsdGVkX19TsTlfFVUGj8Q="
            };
            cryptText.Add(dd[3], cryptTextList.ToArray());
            var IVList = new List<string>()
            {
                "IuPtED6ZqY5x7ZJaZmhxsQ==",
                "2OiKS7E+SsE1I1SUX059qA==",
                "yk6DUFyg/zACWi8HIm5nNA==",
                "Iga0n7QFjo2cd9yqs3/HWA==",
                "jDz4j363OvNa5RCNtySr/g==",
                "vaukQua5jx7mOF5g+b76/w=="
            };
            IV.Add(dd[3], IVList.ToArray());
        }

        static void InitWōden()
        {
            var cryptTextList = new List<string>() {
                "U2FsdGVkX1+KdFdcb3NqgaY=",
                "U2FsdGVkX18Br8lgEsFjmBA=",
                "U2FsdGVkX18vDxlTRm4Z9Js=",
                "U2FsdGVkX18aHNvqpLGmGpA=",
                "U2FsdGVkX18RLezNkG0dApg=",
                "U2FsdGVkX1/8/4oz1uhWaA0="
            };
            cryptText.Add(dd[4], cryptTextList.ToArray());
            var IVList = new List<string>()
            {
                "HpYBR5mVqVni9FsHL5GrVA==",
                "l02UrBF0ph2N4Wmc1M/GFg==",
                "BEPnzwQ0d5zNLwzwnpAqBA==",
                "j/zJXrMeRmQ1O5Knd7sBoA==",
                "dLCct/3j4Ak04QY2nM7R2Q==",
                "jUFSaIL5mvFZP7tSCTP7gA=="
            };
            IV.Add(dd[4], IVList.ToArray());
        }

        static void InitFrigg()
        {
            var cryptTextList = new List<string>() {
                "U2FsdGVkX1/2U8dtdmiKKU8=",
                "U2FsdGVkX1+uXz+T4kGeVa0=",
                "U2FsdGVkX19ohp3Vz5Si20Q=",
                "U2FsdGVkX1/2B4XpM0Q4P3M=",
                "U2FsdGVkX1/wxs+veYvKbZw=",
                "U2FsdGVkX18i+bG49eHbg80="
            };
            cryptText.Add(dd[5], cryptTextList.ToArray());
            var IVList = new List<string>()
            {
                "bfpTEz7mUsflRQ4S85YYNg==",
                "tq0zRJ5UjEOTJ0boW7AsfA==",
                "6bMmrq0gGLklZm7z7gt2BA==",
                "YIXmk0MCO9bTt/4v4kzP2A==",
                "L3YPIZcP7RXsFVJziGs5aw==",
                "du4UozF2bnRz/jyVu1Ozxw=="
            };
            IV.Add(dd[5], IVList.ToArray());
        }

        static void InitSól()
        {
            var cryptTextList = new List<string>() {
                "U2FsdGVkX19Br5pVu4AtRtg=",
                "U2FsdGVkX19C3HWWQ1q6VxE=",
                "U2FsdGVkX1/K7FjQ5Y9rVZg=",
                "U2FsdGVkX19dnTyHDgfMbUg=",
                "U2FsdGVkX1+vSyglrNnpNpE=",
                "U2FsdGVkX19CKMQX6AF8Qbk="
            };
            cryptText.Add(dd[6], cryptTextList.ToArray());
            var IVList = new List<string>()
            {
                "8h2gh5U8SfNNT8TC2zRkMw==",
                "DphXvg2uMt56twAbzgp9DQ==",
                "nxyU8KveOuot2GA1q9P1+Q==",
                "O5oFeHTt5uM3RVtP2hSnbg==",
                "Jf1ZP7obQ3O4An80PTszDg==",
                "Mr1YHU2Wbr2se0JwP3NGnA=="
            };
            IV.Add(dd[6], IVList.ToArray());
        }

        static void Main(string[] args)
        {
            Init();
            for (var i = 0; i < 7; i++)
            {
                var encryptedText = cryptText[dd[i]];
                var iv = IV[dd[i]];

                for (var j = 0; j < encryptedText.Length; j++)
                {
                    var decryptedBytes = Decrypt(Convert.FromBase64String(encryptedText[j]), Convert.FromBase64String(Key), Convert.FromBase64String(iv[j]));
                    Console.WriteLine(Encoding.UTF8.GetString(decryptedBytes));
                }
            }
        }

        public static byte[] Decrypt(byte[] encryptedBytes, byte[] key, byte[] iv)
        {
            using (var csp = new AesCryptoServiceProvider())
            {
                csp.KeySize = 128;
                csp.BlockSize = 128;
                csp.Mode = CipherMode.CFB;
                csp.Padding = PaddingMode.None;
                csp.Key = key;
                csp.IV = iv;

                using (var decryptor = csp.CreateDecryptor())
                using (var mstream1 = new MemoryStream(encryptedBytes.Skip(16).ToArray()))
                using (var cstream = new CryptoStream(mstream1, decryptor, CryptoStreamMode.Read))
                using (var mstream2 = new MemoryStream())
                {
                    cstream.CopyTo(mstream2);
                    return mstream2.ToArray();
                }
            }
        }

        public static byte[] Decrypt(string encryptedString, string password)
        {
            var encryptedBytes = Convert.FromBase64String(encryptedString);
            var salt = encryptedBytes.Skip(8).Take(8).ToArray();
            var kiv = GenerateKIV(salt, password, HashAlgorithmName.SHA512, 10000, 48).ToList();

            using (var csp = new AesCryptoServiceProvider())
            {
                csp.KeySize = 128;
                csp.BlockSize = 128;
                csp.Mode = CipherMode.CFB;
                csp.Padding = PaddingMode.None;
                csp.Key = kiv.GetRange(0, 32).ToArray();
                csp.IV = kiv.GetRange(32, 16).ToArray();

                using (var decryptor = csp.CreateDecryptor())
                using (var mstream1 = new MemoryStream(encryptedBytes.Skip(16).ToArray()))
                using (var cstream = new CryptoStream(mstream1, decryptor, CryptoStreamMode.Read))
                using (var mstream2 = new MemoryStream())
                {
                    cstream.CopyTo(mstream2);
                    return mstream2.ToArray();
                }
            }
        }

        private static IEnumerable<byte> GenerateKIV(byte[] salt, string password, HashAlgorithmName hashAlgorithmName, int iterations, int length)
        {
            var keyGenerator = new Rfc2898DeriveBytes(password, salt, iterations, hashAlgorithmName);
            return keyGenerator.GetBytes(length);
        }
    }
}
 

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
}