SHA-1 Hash Calculator
Compute the 160 bit SHA-1 message digest of a short text string.
What it does
SHA-1 is a message digest algorithm published by the National Institute of Standards and Technology as part of the Secure Hash Standard. It takes an input message and returns a 160 bit value, usually written as 40 hexadecimal digits. RFC 3174 gives the same algorithm in a form that internet developers can implement directly.
The message is first converted to bytes, then padded. A single one bit is appended, followed by enough zero bits to leave 64 bits for the message length at the end of the last 512 bit block. That length field makes messages of different lengths but similar content produce different digests.
Each block is expanded from 16 words into 80 words using a simple XOR and rotation rule. The 80 rounds mix five working variables with bitwise functions and constants that change every 20 rounds. The final working values are added to a fixed starting state to give the digest.
This tool implements the algorithm in your browser and shows the digest, the message length in bits and the number of padded blocks. The known vector for the string abc is included so you can check the result immediately.
SHA-1 has been superseded for security use after practical collision attacks. It still appears in older certificates and protocols, and it remains a useful teaching example of a Merkle-Damgard hash construction.
How to use
- Type a short message into the input box. The page opens on the standard test string abc.
- Read the 40 digit hexadecimal digest in the main result.
- Check the message length in bits, which is the UTF-8 byte count multiplied by eight.
- Check the block count, which is the padded message length divided by 512.
- Confirm the abc vector matches a9993e364706816aba3e25717850c26c9cd0d89d.
- Try a single character change and watch how much the digest changes.
Formula
- A to E
- The five 32 bit working variables, initialised to fixed constants.
- W
- The 80 expanded 32 bit words for the current block.
- K
- A round constant, one of four values used across the 80 rounds.
- f
- A bitwise function that changes every 20 rounds.
- rotl
- Rotate left by the number of bits shown, here 5 or 30.
The engine builds the byte stream using UTF-8 rules, so non ASCII characters become two, three or four bytes. It pads to 56 bytes before adding an eight byte big endian bit length, then processes each 64 byte block with 32 bit unsigned arithmetic.
Worked example
Example: hashing the string abc
Input message abc, three ASCII bytes.
- The message has 3 bytes, so its length is 24 bits.
- Padding adds a single 0x80 marker byte and zeros until the block has 56 bytes, then writes the 64 bit length 24.
- The padded message is exactly one 512 bit block.
- The first 16 words are read from that block, then words 16 through 79 are produced by XOR and rotate left by one.
- Rounds 0 to 19 use the choose function, 20 to 39 use parity, 40 to 59 use majority and 60 to 79 use parity again.
- The five working values are added to the initial constants and written in hexadecimal.
- The tool reports a9993e364706816aba3e25717850c26c9cd0d89d, bits 24 and blocks 1.
Reference table
| Message | Length in bits | SHA-1 digest |
|---|---|---|
| abc | 24 | a9993e364706816aba3e25717850c26c9cd0d89d |
| A | 8 | 6dcd4ce23d88e2ee9568ba546c007c63d9131c1b |
| hello | 40 | aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d |
| Wiki | 32 | 4f983a660ea1223340ae32159c1ab35d5e29bd2f |
| Kami | 32 | 4a90a971f3e2269ef7d3763cfcd1a66cfcd2d5c8 |
Limits
- The input box is capped at 4,096 characters so the browser stays responsive.
- SHA-1 is not collision resistant. Do not use it for new security designs.
- A digest cannot be reversed to recover the original message.
- The tool computes a digest for text only. It does not read files.
Common mistakes
- Treating a SHA-1 digest as proof of identity or authenticity.
- Forgetting that non ASCII characters are encoded as several bytes, which changes the bit length.
- Comparing a hexadecimal digest with a base64 representation of the same hash.
- Assuming a different message cannot produce the same digest, which collisions disprove.
- Using an empty input, which the tool rejects even though the standard defines a digest for it.
Try it yourself
Quick checks. Answers sit tucked under each question.
What is the SHA-1 digest of abc?
a9993e364706816aba3e25717850c26c9cd0d89d. The message is 3 bytes or 24 bits and pads to one block.
How many bits is the hello message?
40 bits, because it has five ASCII bytes. Its digest begins aaf4c61d.
Why is the length field included in padding?
It makes messages with the same byte pattern but different lengths produce different digests and closes a length extension ambiguity.
Questions
What is SHA-1?
A 160 bit message digest algorithm defined in NIST FIPS 180-4 and described for internet use in RFC 3174.
Is SHA-1 secure today?
No. Practical collision attacks exist, so newer designs use SHA-256 or SHA-3.
How long is a SHA-1 digest?
160 bits, written as 40 hexadecimal digits or five 32 bit words.
Can the digest be reversed?
No. A hash is a one way compression, though short messages can sometimes be guessed by brute force.
Why does UTF-8 matter here?
The algorithm hashes bytes, not characters. UTF-8 turns each character into one to four bytes before padding.
What is a test vector?
A published input and expected output pair, such as abc and its digest, used to check an implementation.