def html_hash(html_string):
"""
Generates a simple hash of an HTML document string.
For development purposes only. Not cryptographically secure.
"""
hash_value = 0
for char in html_string:
hash_value = (hash_value * 31 + ord(char)) % (2**32) # Simple polynomial hash
return hash_value
if __name__ == '__main__':
html_doc1 = """
<!DOCTYPE html>
<html>
<head>
<title>Example 1</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
"""
html_doc2 = """
<!DOCTYPE html>
<html>
<head>
<title>Example 2</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
"""
html_doc3 = """
<!DOCTYPE html>
<html>
<head>
<title>Example 3</title>
</head>
<body>
<h2>Another heading</h2>
</body>
</html>
"""
hash1 = html_hash(html_doc1)
hash2 = html_hash(html_doc2)
hash3 = html_hash(html_doc3)
print(f"Hash of doc1: {hash1}")
print(f"Hash of doc2: {hash2}")
print(f"Hash of doc3: {hash3}")
#Test case for empty string
html_doc4 = ""
hash4 = html_hash(html_doc4)
print(f"Hash of doc4: {hash4}")
Add your comment