easy +10 pts

SHA1 Hash String

Compute the SHA1 hex digest of any string using Python's hashlib.

Write a function `sha1_hash_string(s: str) -> str` that takes a string `s` and returns the SHA1 hash of its UTF-8 encoded bytes as a hexadecimal string (lowercase). Use Python's `hashlib` module. The input string may contain any characters, including empty string.

Constraints

Input string length: 0 to 10^5 characters. The function should run in O(n) time and use O(1) extra space.

Example

>>> sha1_hash_string('hello')
'f572d396fae9206628714fb2ce00f72e94f2258f'
>>> sha1_hash_string('')
'da39a3ee5e6b4b0d3255bfef95601890afd80709'
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Encode the string as UTF-8 before hashing.
Use `hashlib.sha1(data).hexdigest()` to get the hexadecimal digest.
Remember to import hashlib.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.