Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Adam White AdamWhiteHat

🏠
Working from home
View GitHub Profile
@AdamWhiteHat
AdamWhiteHat / GenericArithmeticFactory.cs
Created Dec 22, 2020
Generic arithmetic operations with an example
View GenericArithmeticFactory.cs
public static class GenericArithmeticFactory<T>
{
private static Dictionary<ExpressionType, Func<T, T, T>> _binaryOperationDictionary;
private static Func<T, T> _sqrtOperation = null;
static GenericArithmeticFactory()
{
_binaryOperationDictionary = new Dictionary<ExpressionType, Func<T, T, T>>();
}
View IsValidIPv6Address.cs
public static bool IPv6Check(string input)
{
if (string.IsNullOrWhiteSpace(input))
{
return false;
}
if (input.IndexOf("::") != input.LastIndexOf("::")) // 'The "::" can only appear once in an address.'
{
return false;
@AdamWhiteHat
AdamWhiteHat / NumberTheory.Maths.cs
Last active Sep 16, 2021
NumberTheory functions, including Legendre Symbol, Tonelli-Shanks, Chinese Remainder Theorem, Modular Multiplicative Inverse, Primitive Root, Multiplicative Order, Discrete Logarithm, Discrete Root, Eulers Totient Phi, Carmichael Lambda Function, LCM, and GCD.
View NumberTheory.Maths.cs
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
public static class Maths
{
/// <summary>
/// Legendre Symbol returns 1 for a (nonzero) quadratic residue mod p, -1 for a non-quadratic residue (non-residue), or 0 on zero.
/// </summary>