473,412 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

MD5 message digest conversion to 16 byte array

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
11 5229
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
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
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
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

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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CAFxX | last post by:
i'm writing a program that executes some calculations on a bitmap loaded in memory. these calculation ends up with pixel wth values far over 255, but i need them to be between 0 and 255 since i...
5
by: john | last post by:
Here is the short story of what i'm trying to do. I have a 4 sided case labeling printer setting out on one of our production lines. Now then i have a vb.net application that sends data to this...
1
by: Jim Shank | last post by:
I am adding support to my application for Oracle 10g and using Enterprise Library Data Access Application Blocks and trying to determine the best way to convert the GUID's which are stored as...
15
by: C# Learner | last post by:
Hi, I have a string (System.String) which holds some data. This data is encoding in UTF8 (i.e. anywhere in the string where there should be a single 'é' character, there will be two characters...
2
by: iyuen | last post by:
I'm trying to convert byte array (valid bitmap format) into some bitmaps and back to byte array again. But when I inspect the content of the array before and after the conversion they are...
5
by: Jim Hubbard | last post by:
I have some C# code that is supposed to wrap the defrag APIs and I am trying to convert it to VB.Net (2003). But, I keep having problems. The C# code is relatively short, so I'll post it...
0
by: chaitali.pats | last post by:
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 to 16 byte...
5
by: Jamie Risk | last post by:
This is the code snippet that I've come up to convert a byte to string. Is there a best practiced method for such a conversion? - Jamie public static string ByteArrayToString(byte array) {...
0
by: cooljoel27 | last post by:
can any one of youll write a code in microsoft Visual basics for secure Hash algorithm please see additional information below (this is for my final year project) ALGORITHM  Append padding bits...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.