Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

Given a set of SHA1 hash code, if we knew a portion of the plaintext for each particular hash code, and also the remaining portion of the plaintext is a constant value for each hash code. Is it possible for us to recover what is the constant value?

share|improve this question
I guess it depends how long the constant value is... –  Thomas Oct 29 '12 at 19:16
Brute force will do it. How long it takes depends on how many bits there are in the constant value. –  rossum Oct 29 '12 at 21:03
Maybe if you look really really deep into cryptographic analysis of SHA-1 you may shave off a few bits (this may require a masters degree and oodles of memory), but I think normally you are stuck with brute forcing the constant value. If you find a SHA-1 match though you are certain that you've found the right value. –  owlstead Oct 29 '12 at 21:36
Said if I know only first character are different remaining are the same, will it decrease the brute fore time? –  user236501 Oct 30 '12 at 5:58
@user236501: No, every character constant in message except one does not help significantly. Essentially, the best attack we can think of so far is to enumerate the possible values for the constant unknown portion of the message. –  fgrieu Oct 30 '12 at 8:08

1 Answer 1

up vote 2 down vote accepted

Yes, but unless there is a significant break through in the crypto-analysis of SHA-1, the only way to retrieve the constant value is by brute forcing it. In other words, trying all the values, calculating the SHA-1 over the plaintext and the constant and comparing it with the given hash value.

share|improve this answer
Just because nobody seemed to care to actually make their comments an answer :) –  owlstead Oct 31 '12 at 0:13
But we don't know the message length still possible? Any message length will still hash into same bit output right? it is a 40 character output. –  user236501 Oct 31 '12 at 0:48
@user236501 No, but if the constant value is short enough we'll reach it eventually, by going "try every 1-character combination... OK we've tried them all and nothing worked, move on to every 2-character combination" and so on. –  Thomas Oct 31 '12 at 5:00
I found a SHA1 extension attack, if said the hash format is (a||b||constant value), is it possible that I create another hash code (c||b||constant value) without knowing the constant value. –  user236501 Oct 31 '12 at 5:19
@user236501 Possibly, but you wouldn't learn anything about the constant value doing that. –  Thomas Dec 5 '12 at 9:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.