Skip to content

Instantly share code, notes, and snippets.

@i-e-b
Created September 18, 2017 14:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i-e-b/c37cc2d728fe5e5a56205cd7e62d682c to your computer and use it in GitHub Desktop.
Save i-e-b/c37cc2d728fe5e5a56205cd7e62d682c to your computer and use it in GitHub Desktop.
Adler32 hash in C#
private static uint Adler32(string str)
{
const int mod = 65521;
uint a = 1, b = 0;
foreach (char c in str) {
a = (a + c) % mod;
b = (b + a) % mod;
}
return (b << 16) | a;
}
@cartercanedy
Copy link

you could probably implement this with Span<byte> to be encoding agnostic, but ty for putting this up in a gist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment