Generate SHA1 with a certain prefix











up vote
-1
down vote

favorite












I was wondering if there is an algorithm that I can use in order to generate a SHA1 string with a certain prefix by starting from a certain string:



const prefix = '0a12'
const prefix_sha = '111'
suffix = random_str()

while not SHA1(prefix + suffix).starts(prefix_sha):
suffix = update_suffix(suffix)


For example, in this case, the loop must exit when we found an hash which starts with 111. For the hash function I'm using this:



hashlib.sha1(s.encode('utf-8')).hexdigest()


where s is a string.










share|improve this question
























  • What is the aim?
    – kelalaka
    Nov 4 at 12:01










  • What is the aim of your question?
    – Surcle
    Nov 4 at 12:15












  • SHA1 is shattered, but this is different, and you are the one seeking an answer here. The code you write gives no information at all, where is SHA1?
    – kelalaka
    Nov 4 at 12:19






  • 1




    I assume this question is a duplicate of crypto.stackexchange.com/questions/22736/sha1-partial-collision
    – Robert
    Nov 4 at 12:22










  • I updated the pseudocode
    – Surcle
    Nov 4 at 12:23















up vote
-1
down vote

favorite












I was wondering if there is an algorithm that I can use in order to generate a SHA1 string with a certain prefix by starting from a certain string:



const prefix = '0a12'
const prefix_sha = '111'
suffix = random_str()

while not SHA1(prefix + suffix).starts(prefix_sha):
suffix = update_suffix(suffix)


For example, in this case, the loop must exit when we found an hash which starts with 111. For the hash function I'm using this:



hashlib.sha1(s.encode('utf-8')).hexdigest()


where s is a string.










share|improve this question
























  • What is the aim?
    – kelalaka
    Nov 4 at 12:01










  • What is the aim of your question?
    – Surcle
    Nov 4 at 12:15












  • SHA1 is shattered, but this is different, and you are the one seeking an answer here. The code you write gives no information at all, where is SHA1?
    – kelalaka
    Nov 4 at 12:19






  • 1




    I assume this question is a duplicate of crypto.stackexchange.com/questions/22736/sha1-partial-collision
    – Robert
    Nov 4 at 12:22










  • I updated the pseudocode
    – Surcle
    Nov 4 at 12:23













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I was wondering if there is an algorithm that I can use in order to generate a SHA1 string with a certain prefix by starting from a certain string:



const prefix = '0a12'
const prefix_sha = '111'
suffix = random_str()

while not SHA1(prefix + suffix).starts(prefix_sha):
suffix = update_suffix(suffix)


For example, in this case, the loop must exit when we found an hash which starts with 111. For the hash function I'm using this:



hashlib.sha1(s.encode('utf-8')).hexdigest()


where s is a string.










share|improve this question















I was wondering if there is an algorithm that I can use in order to generate a SHA1 string with a certain prefix by starting from a certain string:



const prefix = '0a12'
const prefix_sha = '111'
suffix = random_str()

while not SHA1(prefix + suffix).starts(prefix_sha):
suffix = update_suffix(suffix)


For example, in this case, the loop must exit when we found an hash which starts with 111. For the hash function I'm using this:



hashlib.sha1(s.encode('utf-8')).hexdigest()


where s is a string.







cryptography sha1






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 7:52

























asked Nov 4 at 11:53









Surcle

18913




18913












  • What is the aim?
    – kelalaka
    Nov 4 at 12:01










  • What is the aim of your question?
    – Surcle
    Nov 4 at 12:15












  • SHA1 is shattered, but this is different, and you are the one seeking an answer here. The code you write gives no information at all, where is SHA1?
    – kelalaka
    Nov 4 at 12:19






  • 1




    I assume this question is a duplicate of crypto.stackexchange.com/questions/22736/sha1-partial-collision
    – Robert
    Nov 4 at 12:22










  • I updated the pseudocode
    – Surcle
    Nov 4 at 12:23


















  • What is the aim?
    – kelalaka
    Nov 4 at 12:01










  • What is the aim of your question?
    – Surcle
    Nov 4 at 12:15












  • SHA1 is shattered, but this is different, and you are the one seeking an answer here. The code you write gives no information at all, where is SHA1?
    – kelalaka
    Nov 4 at 12:19






  • 1




    I assume this question is a duplicate of crypto.stackexchange.com/questions/22736/sha1-partial-collision
    – Robert
    Nov 4 at 12:22










  • I updated the pseudocode
    – Surcle
    Nov 4 at 12:23
















What is the aim?
– kelalaka
Nov 4 at 12:01




What is the aim?
– kelalaka
Nov 4 at 12:01












What is the aim of your question?
– Surcle
Nov 4 at 12:15






What is the aim of your question?
– Surcle
Nov 4 at 12:15














SHA1 is shattered, but this is different, and you are the one seeking an answer here. The code you write gives no information at all, where is SHA1?
– kelalaka
Nov 4 at 12:19




SHA1 is shattered, but this is different, and you are the one seeking an answer here. The code you write gives no information at all, where is SHA1?
– kelalaka
Nov 4 at 12:19




1




1




I assume this question is a duplicate of crypto.stackexchange.com/questions/22736/sha1-partial-collision
– Robert
Nov 4 at 12:22




I assume this question is a duplicate of crypto.stackexchange.com/questions/22736/sha1-partial-collision
– Robert
Nov 4 at 12:22












I updated the pseudocode
– Surcle
Nov 4 at 12:23




I updated the pseudocode
– Surcle
Nov 4 at 12:23

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53140536%2fgenerate-sha1-with-a-certain-prefix%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53140536%2fgenerate-sha1-with-a-certain-prefix%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini