How to hash a string: Difference between revisions

From Cuis CookBook
Jump to navigation Jump to search
(imported material)
 
(syntax hilight)
 
Line 1: Line 1:


== Example 1. ==
== Example 1. ==
Sometimes it is useful to make a number that represents string. This is usually called an ''hash'', one of its properties is that if you change the string a tiny bit the hash number becomes quite different.
Sometimes it is useful to make a number that represents string. This is usually called an ''hash'', one of its properties is that if you change the string a tiny bit the hash number becomes quite different.<syntaxhighlight lang="smalltalk">
'Hello world' hash. "=> 136137888 "
'Hello world' hash. "=> 136137888 "
</syntaxhighlight>


== Example 2. MD5 ==
== Example 2. MD5 ==
<syntaxhighlight lang="smalltalk">
WebUtils md5Digest: 'foobar'. => '3858F62230AC3C915F300C664312C63F'
WebUtils md5Digest: 'foobar'. "=>" '3858F62230AC3C915F300C664312C63F'
'''Exercise'''. Try to hash 'Hello World' and see how much different it is.
</syntaxhighlight>'''Exercise'''. Try to hash 'Hello World' and see how much different it is.


'''Exercise'''. Explore the ''Cryptography-DigitalSignatures'' package for another implementation of the hashing function.
'''Exercise'''. Explore the ''Cryptography-DigitalSignatures'' package for another implementation of the hashing function.

Latest revision as of 20:09, 12 May 2025

Example 1.

Sometimes it is useful to make a number that represents string. This is usually called an hash, one of its properties is that if you change the string a tiny bit the hash number becomes quite different.

'Hello world' hash.     "=> 136137888 "


Example 2. MD5

WebUtils md5Digest: 'foobar'.     "=>"   '3858F62230AC3C915F300C664312C63F'

Exercise. Try to hash 'Hello World' and see how much different it is.

Exercise. Explore the Cryptography-DigitalSignatures package for another implementation of the hashing function.