41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
namespace Mishmash;
|
|
|
|
public class Mishmash64
|
|
{
|
|
private UInt64 accumulator;
|
|
public Mishmash64()
|
|
{
|
|
accumulator = 0;
|
|
}
|
|
public override string ToString()
|
|
{
|
|
return accumulator.ToString("X");
|
|
}
|
|
public UInt64 Hash64()
|
|
{
|
|
return accumulator;
|
|
}
|
|
public void Write(string s)
|
|
{
|
|
var (bytes, size) = MishmashEngine.StringToBytesUtf8(s);
|
|
accumulator = MishmashEngine.Engine(bytes, size, accumulator);
|
|
}
|
|
public void Write(byte[] bytes, int size)
|
|
{
|
|
accumulator = MishmashEngine.Engine(bytes, size, accumulator);
|
|
}
|
|
public byte[] Bytes()
|
|
{
|
|
var hash = Hash64();
|
|
List<byte> results = new();
|
|
results.Add((byte)((hash >> 56) & 0x00000000000000FF));
|
|
results.Add((byte)((hash >> 48) & 0x00000000000000FF));
|
|
results.Add((byte)((hash >> 40) & 0x00000000000000FF));
|
|
results.Add((byte)((hash >> 32) & 0x00000000000000FF));
|
|
results.Add((byte)((hash >> 24) & 0x00000000000000FF));
|
|
results.Add((byte)((hash >> 16) & 0x00000000000000FF));
|
|
results.Add((byte)((hash >> 8) & 0x00000000000000FF));
|
|
results.Add((byte)(hash & 0x00000000000000FF));
|
|
return results.ToArray();
|
|
}
|
|
} |