using System;
using System.Text;
using System.IO;
using System.Security.Cryptography;

public class Program
{
public static void Main()
{
Console.WriteLine("https//opensea[.]io/collection/contingency-ocol-44924");
Console.WriteLine();

//CONTINGENCY PROTOCOL 44924 COLLECTION DESCRIPTION
//MD5: 346257E94DA2E0D0D0F54AA397D291F0
//DATA: Q Society
string collectiondescriptiondecoded = "NAKAMOTO";
MD5 md5Hash = MD5.Create();
byte[] md5 = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(collectiondescriptiondecoded));
Console.WriteLine("Verified: [Q Society] = " + BitConverter.ToString(md5).Replace("-", ""));
Console.WriteLine();

//SQME KEYS TO TEST 
byte[] testkey0 = Encoding.UTF8.GetBytes("rustyshackleford");
byte[] testkey1 = Encoding.UTF8.GetBytes("Q H7^PZBVTpZ7302"); 
//https//www[.]britbonglogpost[.]com/978ea96f-2740-4ea6-b1d0-288f11a48ff7.jpg
byte[] testkey2 = HexStringToByteArray("978ea96f-2740-4ea6-b1d0-288f11a48ff7".Replace("-", ""));

//NFT IMAGE DESCRIPTIONS - BASE64 ENCODED DATA
//https[:]//opensea[.]io/assets/0x495f947276749ce646f68ac8c248420045cb7b5e/42715653451494116278904116357368839356782358833774246712130390239617933639681
string omega_b64 = "mbhD5klu/+mMNw6nN8bmE7+m4MWKp9ZMzO61R83YPGc23pCnwNXl6XnRPizFWi+k35YtNRsXiT20P7KNiV6Bz/jwBGq3PjQv2Zd14gORArKA6Cz30JEU9Sa6GGCEpJIufbFJuWWxaI9NTnGCrshcDDvIne9DvhwSTvcJHMOCAkeBNiRwxb/tCK17mclpwgV1fKXDhrCfzddOW2bTO14c0w==";

//https[:]//opensea[.]io/assets/0x495f947276749ce646f68ac8c248420045cb7b5e/42715653451494116278904116357368839356782358833774246712130390238518422011905
string epsilon_b64 = "QWIn8NzJMuDZIfibj/MqK1CPK32YXf3KuzCsf4HohUPSmUgyqAdY6moE98U6v3wVGTu2g1+ZziW+tqk9cVif41v+GC91bgnym7NlX9URAY/LLE9X9amJw3Qxa4PyNWat/dVkEOUFoa3vAE6TCVgk/gfWzB8085VW7A6hBcoR0D1tv9U5HrylObyNdm2I6ljim5XVXA9XRkLKffQReXWkAS7R34IQYsipc9jOaf/LlaCPputybuz5cKWaq/q6kbRksksbPL6v4F/omjkBHOJiqWxKHRkEgSIOEEEgIQHqk5h5Tnf7O7I5/eyDXGPAYBS2I7IwMmykLp7CG9nFLg5FDHmNgQZD4vOFrJcjoYcH3mg=";
//DECODE BASE64
var epsilon = Convert.FromBase64String(epsilon_b64);
var omega = Convert.FromBase64String(omega_b64);

//AES CRYPTO
var crypto = new AesCryptographyService();

Console.WriteLine("Epsilon: " + epsilon_b64);
Console.WriteLine("B64 Decoded: " + BitConverter.ToString(epsilon).Replace("-", ""));
Console.WriteLine("To String: " + Encoding.UTF8.GetString(epsilon));
Console.WriteLine();

var decrypted = crypto.Decrypt(epsilon, testkey0, md5);
Console.WriteLine("Trying Key: " + BitConverter.ToString(testkey0).Replace("-", "") + " IV: " + BitConverter.ToString(md5).Replace("-", ""));
Console.WriteLine("Decrypted: " + BitConverter.ToString(decrypted).Replace("-", ""));
Console.WriteLine("To String" + Encoding.UTF8.GetString(decrypted));
Console.WriteLine();

decrypted = crypto.Decrypt(epsilon, testkey1, md5);
Console.WriteLine("Trying Key: " + BitConverter.ToString(testkey1).Replace("-", "") + " IV: " + BitConverter.ToString(md5).Replace("-", ""));
Console.WriteLine("Decrypted: " + BitConverter.ToString(decrypted).Replace("-", ""));
Console.WriteLine("To String" + Encoding.UTF8.GetString(decrypted)); 
Console.WriteLine();

decrypted = crypto.Decrypt(epsilon, testkey2, md5);
Console.WriteLine("Trying Key: " + BitConverter.ToString(testkey2).Replace("-", "") + " IV: " + BitConverter.ToString(md5).Replace("-", ""));
Console.WriteLine("Decrypted: " + BitConverter.ToString(decrypted).Replace("-", ""));
Console.WriteLine("To String" + Encoding.UTF8.GetString(decrypted)); 
Console.WriteLine();

Console.WriteLine();
Console.WriteLine();

}

public static byte[] HexStringToByteArray(String hex)
{
int NumberChars = hex.Length;
byte[] bytes = new byte[NumberChars / 2];
for (int i = 0; i < NumberChars; i += 2)
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
return bytes;
}
}

public class AesCryptographyService
{
public byte[] Encrypt(byte[] data, byte[] key, byte[] iv)
{
using (var aes = Aes.Create())
{
aes.KeySize = 128;
aes.BlockSize = 128;
aes.Padding = PaddingMode.Zeros;

aes.Key = key;
aes.IV = iv;

using (var encryptor = aes.CreateEncryptor(aes.Key, aes.IV))
{
return PerformCryptography(data, encryptor);
}
}
}

public byte[] Decrypt(byte[] data, byte[] key, byte[] iv)
{
using (var aes = Aes.Create())
{
aes.KeySize = 128;
aes.BlockSize = 128;
aes.Padding = PaddingMode.Zeros;

aes.Key = key;
aes.IV = iv;

using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))
{
return PerformCryptography(data, decryptor);
}
}
}

private byte[] PerformCryptography(byte[] data, ICryptoTransform cryptoTransform)
{
using (var ms = new MemoryStream())
using (var cryptoStream = new CryptoStream(ms, cryptoTransform, CryptoStreamMode.Write))
{
cryptoStream.Write(data, 0, data.Length);
cryptoStream.FlushFinalBlock();

return ms.ToArray();
}
}

} 

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
}