Skip to content

Instantly share code, notes, and snippets.

@mjs3339
mjs3339 / FixedBigIntegerRandomNumberGenerator.cs
Created March 24, 2020 09:18
Fixed BigInteger Random Number Generator
using System;
using System.Security.Cryptography;
public class FixedBigIntegerRandomNumberGenerator : RandomNumberGenerator
{
private readonly int _bitWidthHold;
private readonly byte[] _buffer;
private readonly BigDecimal _dBi;
private readonly FixedBigInteger _maxValueHold = new FixedBigInteger(0, 0);
private readonly JitterCacheRng _crng;
public FixedBigIntegerRandomNumberGenerator(int bitWidth)
@mjs3339
mjs3339 / FixedBigInteger.cs
Created March 24, 2020 09:16
Adjustable Fixed Bit Width Signed Integer 32,64,128,256,...
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Text;
@mjs3339
mjs3339 / ChiSquared.cs
Last active March 24, 2020 09:13
Chi Squared Byte Array Test
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
public static class ChiSquared
{
/// <summary>
@mjs3339
mjs3339 / FileData.cs
Created June 3, 2019 21:04
C# File Data Class
using System;
using System.Diagnostics.Contracts;
using System.IO;
using System.Management;
using System.Runtime.InteropServices;
using System.Security;
using Microsoft.Win32.SafeHandles;
[SecurityCritical]
[Serializable]
@mjs3339
mjs3339 / BigComplex.cs
Last active May 2, 2019 20:34
C# Big Complex Number (Binomial) Class
using System;
using System.Collections.Generic;
public class BigComplex
{
public BigComplex()
{
Real = 0;
Imaginary = 0;
}
public BigComplex(BigDecimal real_part)
@mjs3339
mjs3339 / ComplexFft.cs
Created April 15, 2019 19:20
C# Complex Fast Fourier Transform
using System;
public class ComplexFFT
{
public Complex[] Fft(Complex[] arr)
{
var length = arr.Length;
var hLength = length >> 1;
if (length == 1)
return arr;
var evenCoefficients = new Complex[hLength];
@mjs3339
mjs3339 / CryptoGetBytesExperimental.cs
Last active March 4, 2019 16:27
C# CryptoGetBytesExperimental
using System;
using System.Security.Cryptography;
/// <summary>
/// Murmur3 (128b): 16 MBps.
/// MD5 (128b): 7.5 MBps.
/// SHA1 (160b): 8.5MBps.
/// SHA256: 9.5 MBps.
/// *SHA512: 13.5 MBps.
/// SHA3 (1024b): 12.5 MBps.
/// Tested: I7-8700K @4.2Ghz
@mjs3339
mjs3339 / CryptoEntropySourceExperimental.cs
Created March 4, 2019 15:22
C# CryptoEntropySourceExperimental
#define TESTING
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Threading;
public class CryptoEntropySourceExperimental
{
@mjs3339
mjs3339 / BigIntegerEx.cs
Created March 2, 2019 16:34
C# BigInteger Extension Class
public static class BigIntegerEx
{
private static readonly BigInteger Ten = new BigInteger(10);
private static readonly BigInteger Three = new BigInteger(3);
public static BigInteger ToBigInteger(this char ul)
{
return new BigInteger(ul);
}
public static BigInteger ToBigInteger(this byte ul)
{
@mjs3339
mjs3339 / CryptoRandomNumberGeneratorExperimental.cs
Created February 21, 2019 15:35
C# Crypto Random Number Generator
[Serializable]
public class CryptoRandomNumberGeneratorExperimental : RandomNumberGenerator
{
private const double DBi = 1.0 / ulong.MaxValue;
private readonly CryptoGetBytesExperimental crng = new CryptoGetBytesExperimental();
public bool NextBool()
{
return Sample() < .5;
}
/// <summary>