As mentioned, because SHA-1, like other cryptographic hash functions, is deterministic, you can create a mapping of inputs to outputs, and this is called a rainbow table. This is one of the many reasons why using a plain cryptographic hash function as a password hash is not secure.
However, cryptographic hash functions are specifically designed not to be invertible. SHA-1, like MD5 and SHA-2, are Merkle-Dåmgard hash functions, which basically work like this:
H_n = H_(n-1) + E(M, H_(n-1))
where M
is the message block, H_0
is the initial value, H_n
is the final hash, and E
is the block cipher that's built into the hash function. That is, the message is used as a key in a special-purpose block cipher to encrypt the previous hash value, and the result is added to the previous hash value. This final addition makes it such that the function can't be inverted, since you can't know the output of the block cipher to invert it due to the addition, and because the block cipher is a pseudorandom permutation, it can't be guessed.
Other cryptographic hash functions, such as SHA-3, are based on different designs. The output you see from SHA-3 is only part of a very large (1600-bit) state, so in order to invert it, you'd need to be able to guess a large number of bits (usually 512 or more), which is computationally infeasible.
But, as the rainbow tables show, guessing values is a legitimate option. If the input values are from a set whose possible values are small or easy to guess, then you might want to use HMAC (e.g., HMAC-SHA-256) with a secret key to produce hashes, or, for passwords, a dedicated password hash like Argon2 with a strong salt.