Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:44:57+00:00 2026-06-10T16:44:57+00:00

int main() { SHA256_CTX context; unsigned char md[SHA256_DIGEST_LENGTH]; char *input = NULL; printf(What to

  • 0
int main()
{
 SHA256_CTX context;
 unsigned char md[SHA256_DIGEST_LENGTH];
 char *input = NULL;
 printf("What to hash: ");
 scanf("%m[^\n]%*c", &input);
 size_t length = strlen((const char*)input);
 int i, n=0;
 SHA256_Init(&context);
 SHA256_Update(&context, (unsigned char*)input, length);
 SHA256_Final(md, &context);
 goto NORMAL;
 MORE:
 n++;
 SHA256_Update(&context, md, sizeof(md));
 SHA256_Final(md, &context);
 NORMAL:
 for(i=0; i<SHA256_DIGEST_LENGTH; i++){
   printf("%02x", md[i]);
 }
 printf("\n");
 if(n==5){free(input);exit(0);}
 goto MORE;
 return 0;
}

Why this spaghetti code doesn’t correctly generate multiple hash (sha256)?

My output:

What to hash: paolo
254835d73cc88095a30fc74133beabe9d8463b2954493227b205ea326c8a9c86
f8c9fd41c9aea21015b375af8e30c55df62a74e750f6381c704579b326bff2cd
dbbae564faab81da846c904659e993542fbb20643f7e2f57cc62934dade3ed87
a07424dbf030c30b76eb6db0f32a4ed4af084b4d1523cc2cacefbd19a3d0525d
33041103d21220c8906a3cc0b6369ab38428a440aceb1c5cac963ec471ec1aac
d529745ec47c77aea87d6a5f63ea509223cbd756d77326f232b0cd1d14681e24

expected output (thanks to an online sha256 calculator):

string: paolo
254835d73cc88095a30fc74133beabe9d8463b2954493227b205ea326c8a9c86
afbdc26d1e74bf1e9f68f154883e0bf5a1b9878c5c631e78126b07fa21b79ecd
739efedfc55930ef8cb0d9df487a50ab5b06b7f66594e82e437723df1e6184a1
008f3e3942bfb4289ad8fbbd081e981c4e32ec6508d43d8c3ae10d1b42e792d0
5ec489fc8b5345f43d821b8bac6851d61dc5f4f1fb825a5b74cc18e7bbc3e1b3
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:44:59+00:00Added an answer on June 10, 2026 at 4:44 pm

    The problem is that you’re re-hashing the binary (byte) representation of the resulting hash, and not its hexadecimal representation. You have to convert it to hexadecimal (probably using sprintf() or alike) after every iteration.

    As David Schwartz correctly pointed it out, you also have to re-Init() the hash context in order to clear it and not leave other erroneous data in it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

int main(void) { char *input; printf(prompt>); scanf(%s, input); printf(%s, input); return 0; } prompt>input
int main( ) { char str[200]; int n,tc; scanf(%d,&tc); while(tc--) { scanf(%d,&n); gets(str); puts(str);
int main(int argc, char **args) { unsigned char* str = hallo; printf(String: %s\n,str); uint8_t
int main() { char myString = NULL; realloc(&myString, 5); strncpy((char *)&myString, test, 5); }
int main() { unsigned char a[3]; unsigned char (*p)[3]=NULL; unsigned char *q=NULL; int i
int main() { unsigned int b; signed int a; char z=-1; b=z; a=z; printf(%d
int main(int argc, char** argv) { char *test[5][20]; char *input[20]; int i; for(i=0;i<5;i++){ printf(enter>
int main(int argc, char *argv[]) { printf(Temp is); msgrcv(externalQid, &incomingMsg, sizeof(incomingMsg)-sizeof(long), 0, 0); }
int main() { char *p,c; for(p=Hello World;c=*p;++p) { printf(%c,c); } } In the above
int main() { int p; scanf(%d,&p); fun() { int arr[p]; // isn't this similar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.