{"id":5504,"date":"2026-10-16T16:47:14","date_gmt":"2026-10-16T14:47:14","guid":{"rendered":"https:\/\/www.psyctc.org\/psyctc\/?post_type=docs&#038;p=5504"},"modified":"2026-10-17T14:38:13","modified_gmt":"2026-10-17T12:38:13","password":"","slug":"hashing-and-hash-codes","status":"publish","type":"docs","link":"https:\/\/www.psyctc.org\/psyctc\/glossary2\/hashing-and-hash-codes\/","title":{"rendered":"Hashing and hash codes"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Nothing to do with food.  (I have just discovered that it comes from the lay meaning of hashing: to chop up or make a mess, see <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hash_function#History\" target=\"_blank\" rel=\"noopener\">the history part<\/a> of an excellent Wikipedia article.) <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Details<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Hashing is a one way conversion of a set of data to a set of data that looks  like gibberish but which preserves a 1:1 relationship with the hashed data.  Suppose you had data with participants&#8217; names like this.<\/p>\n\n\n\n<table id=\"tablepress-7\" class=\"tablepress tablepress-id-7\">\n<tbody class=\"row-striping\">\n<tr class=\"row-1\">\n\t<td class=\"column-1\">\"Chris Evans\"<\/td>\n<\/tr>\n<tr class=\"row-2\">\n\t<td class=\"column-1\">\"John Smith\"<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">\"Jane Doe\"<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">\"Cyril Brown\"<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">\"Chris Evans\"<\/td>\n<\/tr>\n<tr class=\"row-6\">\n\t<td class=\"column-1\">\"Jane Doe\"<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-7 from cache -->\n\n\n\n<p class=\"wp-block-paragraph\">Then hash codes for those names might be like this.<\/p>\n\n\n\n<table id=\"tablepress-8\" class=\"tablepress tablepress-id-8\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">V1<\/th><th class=\"column-2\">hashVal<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">\"Chris Evans\"<\/td><td class=\"column-2\">61be1b8203762e2e44125bf2cc349f0be8396ccdc6c4459805bc5190bdd38b1f<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">\"John Smith\"<\/td><td class=\"column-2\">37def76d8e1831e6fd5b8242a23a63ffda5d4ff564055239b90f665f7b288d91<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">\"Jane Doe\"<\/td><td class=\"column-2\">f92677b38e01d005619d8c03339858767f6d665ad98473f2a9d1939cb78d4e92<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">\"Cyril Brown\"<\/td><td class=\"column-2\">8289e99db0654909336f396c76da65e16cfaae3908e7f407816a7edee9ce80b9<\/td>\n<\/tr>\n<tr class=\"row-6\">\n\t<td class=\"column-1\">\"Chris Evans\"<\/td><td class=\"column-2\">61be1b8203762e2e44125bf2cc349f0be8396ccdc6c4459805bc5190bdd38b1f<\/td>\n<\/tr>\n<tr class=\"row-7\">\n\t<td class=\"column-1\">\"Jane Doe\"<\/td><td class=\"column-2\">f92677b38e01d005619d8c03339858767f6d665ad98473f2a9d1939cb78d4e92<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-8 from cache -->\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s a tiny example but what you can see is that the hash codes for the two repeated names &#8220;Chris Evans&#8221; and &#8220;Jane Doe&#8221; remain the same and you can probably see that each distinct name got its own hashed value.  This makes it easy to pseudonymise your data: you are not completely anonymising it, which would throw away the ability to know that the data from &#8220;Chris Evans&#8221; are from the rows with that name (and likewise, for &#8220;Jane Doe&#8221;) and hashing also ensures that the distinct names get distinct hash codes.  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are various algorithms to create hash codes (those were generated using the sha512 function from the <a href=\"https:\/\/jeroen.r-universe.dev\/openssl\" target=\"_blank\" rel=\"noopener\">openssl R package<\/a> and all of them require that you give the program a key, a short word or phrase (I used &#8220;sausages&#8221;). You can do this for your own data using my shiny package <a href=\"https:\/\/shiny.psyctc.org\/apps\/Hashing_IDs\/\" target=\"_blank\" rel=\"noopener\">here<\/a>.  What all the algorithms share is that you can&#8217;t get back from the hashed values to the original values.  Different algorithms can handle larger numbers of unique values to hash without eventually giving two original values the same hashed value.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Try also<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/anonymisation\/\">Anonymisation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/confidentiality\/\">Confidentiality<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/de-anonymisation\/\">De-anonymisation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/pseudonymisation\/\">Pseudonymisation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/shiny-server-apps\/\">Shiny (apps and R package\/code)<\/a><\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Chapters<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Not covered in the OMbook.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Online resources<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">My shiny app, which will give you hash codes for a set of data you upload, is <a href=\"https:\/\/shiny.psyctc.org\/apps\/Hashing_IDs\/\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Dates<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">First created 16.x.26, tweaked 17.x.26.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nothing to do with food. (I have just discovered that it comes from the lay meaning of hashing: to chop up or make a mess, see the history part of an excellent Wikipedia article.) Details Hashing is a one way conversion of a set of data to a set of data that looks like gibberish &hellip; <a href=\"https:\/\/www.psyctc.org\/psyctc\/glossary2\/hashing-and-hash-codes\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Hashing and hash codes<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[],"doc_tag":[],"glossaries":[],"knowledge_base":[],"class_list":["post-5504","docs","type-docs","status-publish","hentry"],"year_month":"2026-10","word_count":317,"total_views":"11","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"chris","author_nicename":"chris","author_url":"https:\/\/www.psyctc.org\/psyctc\/author\/chris\/"},"doc_category_info":[],"doc_tag_info":[],"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/docs\/5504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/comments?post=5504"}],"version-history":[{"count":10,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/docs\/5504\/revisions"}],"predecessor-version":[{"id":5530,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/docs\/5504\/revisions\/5530"}],"wp:attachment":[{"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/media?parent=5504"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/doc_category?post=5504"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/doc_tag?post=5504"},{"taxonomy":"glossaries","embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/glossaries?post=5504"},{"taxonomy":"knowledge_base","embeddable":true,"href":"https:\/\/www.psyctc.org\/psyctc\/wp-json\/wp\/v2\/knowledge_base?post=5504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}