{"id":358,"date":"2021-01-03T07:04:44","date_gmt":"2021-01-03T07:04:44","guid":{"rendered":"https:\/\/michaeljohnsteiner.com\/?p=358"},"modified":"2021-01-03T10:26:18","modified_gmt":"2021-01-03T10:26:18","slug":"fnv1a128b-cs","status":"publish","type":"post","link":"https:\/\/michaeljohnsteiner.com\/index.php\/2021\/01\/03\/fnv1a128b-cs\/","title":{"rendered":"FNV1a128b.cs"},"content":{"rendered":"\n<p>FNV1a Patterned 128Bit Hashing Algorithm using BigInteger <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using System.Numerics;\nusing System.Security.Cryptography;\npublic class FNV1a128b : HashAlgorithm\n{\n    private readonly BigInteger K = \"309485009821345068724781371\".BigIntegerBase10();\n    private readonly BigInteger M = \"340282366920938463463374607431768211456\".BigIntegerBase10();\n    private          BigInteger _hash;\n    private readonly BigInteger Seed = \"144066263297769815596495629667062367629\".BigIntegerBase10();\n    public FNV1a128b()\n    {\n        _hash = Seed;\n    }\n    public FNV1a128b(BigInteger seed)\n    {\n        Seed  = seed;\n        _hash = Seed;\n    }\n    public override int HashSize => 128;\n    public override void Initialize()\n    {\n        _hash = Seed;\n    }\n    protected override void HashCore(byte[] bytes, int ibStart, int cbSize)\n    {\n        Hash128(bytes, ibStart, cbSize);\n    }\n    protected override byte[] HashFinal()\n    {\n        return _hash.ToByteArray();\n    }\n    private unsafe void Hash128(byte[] bytes, int ibStart, int cbSize)\n    {\n        fixed (byte* pb = bytes)\n        {\n            var np = pb + ibStart;\n            for (; cbSize > 0; --cbSize, np++)\n                _hash = ((_hash ^ *np) * K) % M;\n        }\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>FNV1a Patterned 128Bit Hashing Algorithm using BigInteger<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[67,14,166,76],"_links":{"self":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/358"}],"collection":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/comments?post=358"}],"version-history":[{"count":2,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/358\/revisions"}],"predecessor-version":[{"id":360,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/358\/revisions\/360"}],"wp:attachment":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/media?parent=358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/categories?post=358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/tags?post=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}