By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,188 Members | 965 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,188 IT Pros & Developers. It's quick & easy.

MD5 message digest conversion to 16 byte array

P: n/a
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

Jun 26 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
ch***********@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.
Jun 26 '06 #2

P: n/a
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:
ch***********@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.


Jun 26 '06 #3

P: n/a
ch***********@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:
ch***********@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.


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.
Jun 26 '06 #4

P: n/a
ch***********@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.
Jun 26 '06 #5

P: n/a

Chris McDonald wrote:
ch***********@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.


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

Jun 26 '06 #6

P: n/a
ch***********@gmail.com wrote:
Skarmander wrote:
ch***********@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?


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.
Jun 26 '06 #7

P: n/a
ch***********@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

Jun 26 '06 #8

P: n/a
Tom St Denis wrote:
Chris McDonald wrote:
ch***********@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.


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 .

Jun 27 '06 #9

P: n/a

Skarmander wrote:
ch***********@gmail.com wrote:
Skarmander wrote:
ch***********@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?


> 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.


Thanks for your help . :-)

Jun 27 '06 #10

P: n/a
ch***********@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 week.... 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

Jun 27 '06 #11

P: n/a
Tom St Denis wrote:
ch***********@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"...

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 cool.
Everyone seems to want to start with zero knowledge and be a senior
software developer the next week.... 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.
Jun 27 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.