473,387 Members | 1,749 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,387 software developers and data experts.

MD5 hash for url and utf unicode converting to ascii

I would like to convert url into md5 hash. My question is that md5
hash will create collision at 2^64. If you do long(value,16), where
value is the md5 hash string, would value returned from long(value,
16) be unique as long as md5 hashed string is unique? when you move
md5 hashed string to long, where will the collision occur, at anything
>= 2^64?
hash = md5.new()
hash.update("some_url_")
value = hash.digest()
value_in_int = long(value, 16) #would this be unique as long as
hashed string is unique(i.e < 2^64)
hash = md5.new() hash.update("some_url_") value = hash.digest()
value_in_int = long(value, 16) #would this be unique as long as hashed
string is unique(i.e < 2^64)

Do I need to also convert the value to base64.encodestring(value)?
What is the purpose of base64.encodestring?

For unicode encoding, I can do, md5.update(value.encode('utf-8')) to
give me ascii values.
Thank you,
j
Jun 27 '08 #1
2 5789
joe shoemaker wrote:
I would like to convert url into md5 hash. My question is that md5
hash will create collision at 2^64. If you do long(value,16), where
value is the md5 hash string, would value returned from long(value,
16) be unique as long as md5 hashed string is unique? when you move
md5 hashed string to long, where will the collision occur, at anything
MD5's are not meant to be unique keys. They are designed to make it
difficult to alter the original value and maintain the same hash. This
prevents both errors and malevolent data tampering.
Also note, I believe MD5 are typically 128 bits long, not 64, but the
calculation for collision is more complicated than that.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Jun 27 '08 #2
joe shoemaker <jo***********@gmail.comwrote:
I would like to convert url into md5 hash. My question is that md5
hash will create collision at 2^64. If you do long(value,16), where
value is the md5 hash string, would value returned from long(value,
16) be unique as long as md5 hashed string is unique? when you move
md5 hashed string to long, where will the collision occur, at anything
= 2^64?

hash = md5.new()
hash.update("some_url_")
value = hash.digest()
value_in_int = long(value, 16) #would this be unique as long as
hashed string is unique(i.e < 2^64)
hash = md5.new() hash.update("some_url_") value = hash.digest()
value_in_int = long(value, 16) #would this be unique as long as hashed
string is unique(i.e < 2^64)
MD5 Sums don't guarantee uniqueness for any length of string.

If your hash had as many or more bits in as the input string then
there are hashes which are guaranteed unique, but MD5 isn't one of
them. You could (lets say) AES encrypt the string instead.
Do I need to also convert the value to base64.encodestring(value)?
What is the purpose of base64.encodestring?
To turn the buffer into printable characters. You can do it like this also...
>>import md5
hash = md5.new()
hash.update("some_url_")
value = hash.digest()
value
'\xc9\x11}\x8f?64\x83\xf3\xcaPz\x1d!\xddd'
>>value.encode("hex")
'c9117d8f3f363483f3ca507a1d21dd64'
>>long(value.encode("hex"), 16)
267265642849753964132104960801656397156L
>>>
For unicode encoding, I can do, md5.update(value.encode('utf-8')) to
give me ascii values.
Yes that would be fine

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Peter Wilkinson | last post by:
Hello tlistmembers, I am using the encoding function to convert unicode to ascii. At one point this code was working just fine, however, now it has broken. I am reading a text file that has is...
0
by: Luk Vloemans | last post by:
Hi, I've got a Byte consisting of Unicode characters. (16bit) Is there an easy function to convert this Byte into an ASCII format ? Thanks for any assistance. Luk Vloemans IT Student
7
by: Zach | last post by:
Can one convert Unicode to ASCII? If so, could you please give an example? Many thanks.
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
2
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
How do I convert from unicode to ascii string in C++/CLI?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.