PKHeX/PKHeX.Core/Saves/Encryption/SwishCrypto/FnvHash.cs
Kurt 7cfdb8a466 Move hashing to SCBlockAccessor, fix #3455
Fixes #3455 by adding bool for insular sea, and adjusting overall progress values as listed.
Closes #3456 (supersedes)

Updates SCBlockAccessor to eliminate bounds check (integer overflow, which isn't possible with our array size), adds some overloads, and xmldoc.

Co-Authored-By: Jonathan Herbert <3344332+foohyfooh@users.noreply.github.com>
2022-03-02 18:05:13 -08:00

45 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
namespace PKHeX.Core;
/// <summary>
/// FowlerNollVo non-cryptographic hash
/// </summary>
/// <remarks>https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function</remarks>
public static class FnvHash
{
private const ulong kFnvPrime_64 = 0x00000100000001b3;
private const ulong kOffsetBasis_64 = 0xCBF29CE484222645;
/// <summary>
/// Gets the hash code of the input sequence via the alternative Fnv1 method.
/// </summary>
/// <param name="input">Input sequence</param>
/// <param name="hash">Initial hash value</param>
/// <returns>Computed hash code</returns>
public static ulong HashFnv1a_64(ReadOnlySpan<char> input, ulong hash = kOffsetBasis_64)
{
foreach (var c in input)
{
hash ^= c;
hash *= kFnvPrime_64;
}
return hash;
}
/// <summary>
/// Gets the hash code of the input sequence via the alternative Fnv1 method.
/// </summary>
/// <param name="input">Input sequence</param>
/// <param name="hash">Initial hash value</param>
/// <returns>Computed hash code</returns>
public static ulong HashFnv1a_64(ReadOnlySpan<byte> input, ulong hash = kOffsetBasis_64)
{
foreach (var c in input)
{
hash ^= c;
hash *= kFnvPrime_64;
}
return hash;
}
}