{"id":296,"date":"2020-12-17T21:58:08","date_gmt":"2020-12-17T21:58:08","guid":{"rendered":"https:\/\/michaeljohnsteiner.com\/?p=296"},"modified":"2020-12-18T13:16:40","modified_gmt":"2020-12-18T13:16:40","slug":"mapping256bitto32bithash-cs","status":"publish","type":"post","link":"https:\/\/michaeljohnsteiner.com\/index.php\/2020\/12\/17\/mapping256bitto32bithash-cs\/","title":{"rendered":"Mapping256BitTo32BitHash.cs"},"content":{"rendered":"\n<p>Mapping 256Bit Hash to 32Bit Indexed Hash<\/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.Security.Cryptography;\npublic class Mapping256BitTo32BitHash : HashAlgorithm\n{\n    private readonly SHA256Managed                  hasher = new SHA256Managed();\n    public readonly  TinyDictionary&lt;byte[], byte[]> map    = new TinyDictionary&lt;byte[], byte[]>(101, new ArrayComparer());\n    private          byte[]                         h160;\n    public override  int                            HashSize => 32;\n    public override void Initialize()\n    {\n    }\n    protected override void HashCore(byte[] bytes, int ibStart, int cbSize)\n    {\n        h160 = hasher.ComputeHash(bytes, ibStart, cbSize);\n        map.Add(h160, bytes);\n    }\n    protected override byte[] HashFinal()\n    {\n        HashValue = (byte[])map.FindKeyIndex(h160).GetBytes().Clone();\n        return HashValue;\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Mapping 256Bit Hash to 32Bit Indexed Hash<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[89,143,144,142],"_links":{"self":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/296"}],"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=296"}],"version-history":[{"count":2,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/296\/revisions"}],"predecessor-version":[{"id":300,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/296\/revisions\/300"}],"wp:attachment":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/media?parent=296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/categories?post=296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/tags?post=296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}