ln.crypto.ec/ln.crypto.ec/Extensions.cs

49 lines
1.3 KiB
C#

using System;
using System.Globalization;
using System.Numerics;
namespace ln.crypto.ec
{
public static class Extensions
{
public static T[] Segment<T>(this T[] a,int start) => Segment(a, start, a.Length);
public static T[] Segment<T>(this T[] a,int start, int length)
{
T[] r = new T[length];
Array.Copy(a, start, r, 0, length > a.Length ? a.Length : length);
return r;
}
public static byte[] GetBytes(this uint[] a)
{
byte[] r = new byte[a.Length * 4];
for (int n=0;n<a.Length;n++)
Array.Copy(BitConverter.GetBytes(a[n]),0,r,(n*4),4);
return r;
}
public static byte[] GetBytes(this int[] a)
{
byte[] r = new byte[a.Length * 4];
for (int n=0;n<a.Length;n++)
Array.Copy(BitConverter.GetBytes(a[n]),0,r,(n*4),4);
return r;
}
public static T[] Reverse<T>(T[] a)
{
T[] r = (T[])a.Clone();
Array.Reverse(r);
return r;
}
public static int CreateHashCode(this byte[] bytes)
{
int hash = 0x22447799;
foreach (byte by in bytes)
hash *= by;
return hash;
}
}
}