Skip to content

Instantly share code, notes, and snippets.

View trcio's full-sized avatar

patricio trcio

  • Texas
  • 07:56 (UTC -05:00)
View GitHub Profile
@trcio
trcio / Aes.cs
Last active August 29, 2015 14:05
Simple AES wrapper
using System.Security.Cryptography;
public static class Aes
{
public static byte[] Encrypt(byte[] data, byte[] key)
{
if (data == null)
throw new ArgumentNullException("data");
if (key == null)
throw new ArgumentNullException("key");
@trcio
trcio / PasteSxProvider.cs
Created September 1, 2014 04:53
A fully-featured paste.sx API wrapper.
using System;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
namespace PasteSx
{
@trcio
trcio / ConsoleMenu.cs
Last active August 29, 2015 14:07
Easy way to implement menu's into your console program
using System;
using System.Collections.Generic;
namespace ConsoleMenu
{
public class ConsoleMenu
{
private readonly List<MenuOption> Options;
public delegate void ConsoleMenuOptionSelectedEventHandler(ConsoleMenuOptionSelectedEventArgs e);
@trcio
trcio / UserPrefs.cs
Last active August 29, 2015 14:08
Stores and accesses user preferences between sessions. Based off of Unity's PlayerPrefs class: http://docs.unity3d.com/ScriptReference/PlayerPrefs.html
using System;
using System.Reflection;
using Microsoft.Win32;
/// <summary>
/// Stores and accesses user preferences between sessions.
/// </summary>
public static class UserPrefs
{
private static readonly RegistryKey MainKey;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Xml.Serialization;
using Org.BouncyCastle.Asn1.Sec;
namespace BitcoinTools
@trcio
trcio / GAuthProvider.cs
Last active September 23, 2017 17:26
A small, lightweight class to create codes for use with the Google Authenticator app
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Web;
namespace GAuthWrapper
{
public static class GAuthProvider
{
public static int CodeLength { get; set; }
@trcio
trcio / MbamGen.php
Last active August 29, 2015 14:12
CREDITS GO TO MR TRVP
<?php
class MbamGen {
public function get_key() {
$data = [
'id' => $this->random_char() . $this->random_char() . $this->random_char() . $this->random_char() . $this->random_char(),
'key' => ''
];
$hash = strtoupper(md5($data['id']));
function getKey(identifier) {
var chars = '0123456789ABCDEFGHJKLMNPQRTUVWXY',
hash = CryptoJS.MD5(identifier).toString().toUpperCase(),
parts = [];
for (var i = 0; i < 32; i += 2) {
var nextDigit = parseInt(hash.substr(i, 2), 16) & 31,
withDash = (((i % 8) == 0) && (i > 0));
parts.push(withDash ? '-' : '');
@trcio
trcio / OpticCdn.cs
Last active August 29, 2015 14:17
A simple bypass of opticcdn protection, set the cookie "optic_auth" to the value the method returns (returns null on failure)
public static string GetOpticCdnCookie(string source)
{
var matches = Regex.Matches(source, "var .* = \"(.*)\"");
if (matches.Count != 10) return null;
var combined = string.Concat(matches[0].Groups[1].Value, matches[1].Groups[1].Value,
matches[2].Groups[1].Value, matches[3].Groups[1].Value, matches[8].Groups[1].Value,
matches[9].Groups[1].Value, matches[4].Groups[1].Value, matches[5].Groups[1].Value,
matches[6].Groups[1].Value, matches[7].Groups[1].Value);
using (var sha = new SHA1Managed())
{
@trcio
trcio / ChangeCalculator.cs
Last active August 29, 2015 14:22
Finding the least amount of bills/coins for any monetary value (using common bills/coins, no $2 bill, 50 cent coin, etc)
public class ChangeCalculator
{
public static Dictionary<decimal, decimal> GetUsdChange(decimal dollars)
{
return GetChange(dollars, new[] {100, 50, 20, 10, 5, 1, .25M, .10M, .05M, .01M});
}
public static Dictionary<decimal, decimal> GetChange(decimal amount, IEnumerable<decimal> denominations)
{
denominations = denominations.OrderByDescending(i => i);