For Programmers: Free Programming Magazines  


Home > Archive > C > June 2006 > MD5 message digest conversion to 16 byte array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author MD5 message digest conversion to 16 byte array
chaitali.pats@gmail.com

2006-06-26, 3:57 am

Hi ,

I have implemented MD5 in C language . I am getting an output of 32
bits Hexadecimal number . for example :

83a80d3ca057492f0ce99ac1db8dced0

I need to convert this string same to 16 byte array.
Can anyone help me ?

Thanks a lot !!!
Chaitali

Skarmander

2006-06-26, 3:57 am

chaitali.pats@gmail.com wrote:
> Hi ,
>
> I have implemented MD5 in C language . I am getting an output of 32
> bits Hexadecimal number . for example :
>
> 83a80d3ca057492f0ce99ac1db8dced0
>

That's not a 32-bit hexadecimal number by any interpretation of that phrase;
that's a string.

> I need to convert this string same to 16 byte array.


If you actually implemented MD5, it's not likely that you want this. You can
change the code that produces the string above to output a byte array instead.

If, on the other hand, you're writing a function that has to take a string
like this and turn it into a byte array, that's a different matter.

> Can anyone help me ?
>

Since your question does not appear to involve anything that's C specific
and doesn't include any code, it's rather hard to help you.

MD5 is a very common algorithm. Have you tried checking whether Google is
your friend in this case?

S.
chaitali.pats@gmail.com

2006-06-26, 3:57 am

Thanks .
Sorry for putting an incomplete question .
Actually you are right . I need to convert this string to byte array .
Can you help me how to convert the string into byte array because I
think there is some padding issues involved in the conversion,



Skarmander wrote:
> chaitali.pats@gmail.com wrote:
> That's not a 32-bit hexadecimal number by any interpretation of that phrase;
> that's a string.
>
>
> If you actually implemented MD5, it's not likely that you want this. You can
> change the code that produces the string above to output a byte array instead.
>
> If, on the other hand, you're writing a function that has to take a string
> like this and turn it into a byte array, that's a different matter.
>
> Since your question does not appear to involve anything that's C specific
> and doesn't include any code, it's rather hard to help you.
>
> MD5 is a very common algorithm. Have you tried checking whether Google is
> your friend in this case?
>
> S.


Neil

2006-06-26, 3:57 am

chaitali.pats@gmail.com wrote:
> Thanks .
> Sorry for putting an incomplete question .
> Actually you are right . I need to convert this string to byte array .
> Can you help me how to convert the string into byte array because I
> think there is some padding issues involved in the conversion,
>
>
>
> Skarmander wrote:
>


There are may ways.
one is to make the array 0123456789ABCDE ( match the case to you input)

start from the MSD find the char in the array add the position to total.
mult by 16 and move to the next digit.

Starting from the LSD you will need to use a multiplier variable.
Chris McDonald

2006-06-26, 3:57 am

chaitali.pats@gmail.com writes:

>Thanks .
>Sorry for putting an incomplete question .
>Actually you are right . I need to convert this string to byte array .
>Can you help me how to convert the string into byte array because I
>think there is some padding issues involved in the conversion,



I find it extremely difficult to believe that you've been able to
(correctly) implement the MD5 algorithm, but are unable to convert a
string input to a byte array. Anyway, I could be wrong, so, good luck
with your problem.

--
Chris.
Tom St Denis

2006-06-26, 7:56 am


Chris McDonald wrote:
> chaitali.pats@gmail.com writes:
>
>
>
> I find it extremely difficult to believe that you've been able to
> (correctly) implement the MD5 algorithm, but are unable to convert a
> string input to a byte array. Anyway, I could be wrong, so, good luck
> with your problem.


Are you <SHOCK> suggesting that they randomly picked up code off the
web and pasted it into their application without really knowing what
they are doing?

It's almost as if people should write pre-packaged bodies, if not in
the form of a library, of cryptographic algorithms and protocols for
just such an occasion. That it should ALSO be accessible by some form
of web page searching function, almost like a web search.

:-)

Tom

Skarmander

2006-06-26, 6:56 pm

chaitali.pats@gmail.com wrote:
> Skarmander wrote:
>
> Thanks .
> Sorry for putting an incomplete question .
> Actually you are right . I need to convert this string to byte array .
> Can you help me how to convert the string into byte array because I
> think there is some padding issues involved in the conversion,
>

Don't top-post, please. Put your reply at the bottom.

There are no padding issues involved if you are always converting an even
number of hexadecimal digits into a contiguous sequence of bytes.

The function you'll be writing will look something like this:

void hexstring_to_bytes(const char *str, unsigned char *bytes, size_t
len) {
size_t n;
for (n = 0; n < len; n += 2) {
bytes[n / 2] = hexdigit_to_int(str[n]) * 16 +
hexdigit_to_int(str[n + 1]);
}
}

Figuring out how to properly call this function and writing
hexdigit_to_int() are left as exercises. Also, think about how to handle
improper input.

S.
Default User

2006-06-26, 6:56 pm

chaitali.pats@gmail.com wrote:

> Thanks .


Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the other 99% of the posts in this
group.




Brian

chaitali.pats@gmail.com

2006-06-26, 9:56 pm

Tom St Denis wrote:
> Chris McDonald wrote:
>
> Are you <SHOCK> suggesting that they randomly picked up code off the
> web and pasted it into their application without really knowing what
> they are doing?
>
> It's almost as if people should write pre-packaged bodies, if not in
> the form of a library, of cryptographic algorithms and protocols for
> just such an occasion. That it should ALSO be accessible by some form
> of web page searching function, almost like a web search.
>
> :-)
>
> Tom


I had tried everything . But it didn't work .
That's why thought of asking help .
anyway .. now i think i shouldn't have .

chaitali.pats@gmail.com

2006-06-26, 9:56 pm


Skarmander wrote:
> chaitali.pats@gmail.com wrote:
> Don't top-post, please. Put your reply at the bottom.
>
> There are no padding issues involved if you are always converting an even
> number of hexadecimal digits into a contiguous sequence of bytes.
>
> The function you'll be writing will look something like this:
>
> void hexstring_to_bytes(const char *str, unsigned char *bytes, size_t
> len) {
> size_t n;
> for (n = 0; n < len; n += 2) {
> bytes[n / 2] = hexdigit_to_int(str[n]) * 16 +
> hexdigit_to_int(str[n + 1]);
> }
> }
>
> Figuring out how to properly call this function and writing
> hexdigit_to_int() are left as exercises. Also, think about how to handle
> improper input.
>
> S.


Thanks for your help . :-)

Tom St Denis

2006-06-26, 9:56 pm

chaitali.pats@gmail.com wrote:
> I had tried everything . But it didn't work .
> That's why thought of asking help .
> anyway .. now i think i shouldn't have .


How did you implement MD5 and end up with ASCII encoded bytes? You
wrote "I have implemented MD5 in C language"...

Well I too have implement MD5, and the end result of the hash function
is an array of 16 bytes. I'm giving you a hard time because I know you
just copy/pasted code you found on the net. Because you're a lying
thief who can't own up to the fact you didn't implement the algorithm.
You just found code and want to make it do something. Maybe you should
learn how to use the C language first?

I mean seriously people. When I was growing up I taught myself a lot
of functional C by writing really stupid and lame programs. I wasn't
trying to write Doom myself when I was 12, I was trying to get a red
pixel on the screen or draw a line or whatever.

Everyone seems to want to start with zero knowledge and be a senior
software developer the next w.... It takes hard work and
professionalism to become a developer. To think otherwise mocks the
hard work the rest of us have done to get where we are.

..... /rant

Tom

Skarmander

2006-06-27, 3:56 am

Tom St Denis wrote:
> chaitali.pats@gmail.com wrote:
>
> How did you implement MD5 and end up with ASCII encoded bytes? You
> wrote "I have implemented MD5 in C language"...
>

English is obviously not his native language. To you "implemented" probably
implies "developed from scratch"; to him it likely means no more than
"managed to get to work".

> Well I too have implement MD5, and the end result of the hash function
> is an array of 16 bytes. I'm giving you a hard time because I know you
> just copy/pasted code you found on the net.


This is likely.

> Because you're a lying thief who can't own up to the fact you didn't
> implement the algorithm.


This is overly harsh.

> You just found code and want to make it do something. Maybe you should
> learn how to use the C language first?
>

This is good advice.

> I mean seriously people. When I was growing up I taught myself a lot
> of functional C by writing really stupid and lame programs. I wasn't
> trying to write Doom myself when I was 12, I was trying to get a red
> pixel on the screen or draw a line or whatever.
>

I remember writing a program that did wireframe 3D (this was before Doom
existed, or I would have probably wanted solid 3D :-) I copied the
projection formulas from a book, since I had no idea how they worked. I just
wanted 3D, since it was .

> Everyone seems to want to start with zero knowledge and be a senior
> software developer the next w.... It takes hard work and
> professionalism to become a developer. To think otherwise mocks the
> hard work the rest of us have done to get where we are.
>

Take pride in your own achievements; don't worry too much about how others'
are valued, unless you can change something about it.

Mundus vult decipi, ergo decipiatur.

S.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com