MD5 message digest conversion to 16 byte array

C

chaitali.pats

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
 
S

Skarmander

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

chaitali.pats

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,
 
N

Neil

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,

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

Chris McDonald

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

Tom St Denis

Chris said:
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
 
S

Skarmander

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

Default User


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
 
C

chaitali.pats

Tom said:
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 .
 
C

chaitali.pats

Skarmander said:
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 . :)
 
T

Tom St Denis

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
 
S

Skarmander

Tom said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top