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

wired md5 hashing problem

Hello list-members

i am in the process of writing a python script to backup my data. Now I
would like to implement md5/sha1 hashes.

# do md5 fingerprinting
if config.get("global", "crc") == "md5":
m = md5.new()
# open the file
f = open(fname, "rb")
while 1:
block = f.read(1024*1024)
if not block:
break
# generate the hash
m.update(block)
f.close()

# write the results properly formated to a file
fd = file(fname + ".md5", "w")
fd.write(m.hexdigest())
fd.write(" " + fname + "\n")
fd.close()
mguentert@uranos > md5sum -c backup.tar.bz2.md5
/fileservice/temp/backup.tar.bz2: FAILED
md5sum: WARNING: 1 of 1 computed checksum did NOT match

mguentert@uranos > cat backup.tar.bz2.md5
d41d8cd98f00b204e9800998ecf8427e /fileservice/temp/backup.tar.bz2

so the format should be okay, but whats wrong with my piece of code?!

Greetings

--
Mit freundlichen Grüßen

Matthias Güntert

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (GNU/Linux)

iD8DBQBEJquauQEWmvzea70RArn0AKC+ktZwzHUcXY+qqgN+Yj 50p5ilzACdE7X5
+apebd9xy1GCHeRGhHbw3Hc=
=ZDGF
-----END PGP SIGNATURE-----

Mar 26 '06 #1
1 1014
Matthias Güntert <Ma***********@gmx.de> writes:
i am in the process of writing a python script to backup my data. Now I
would like to implement md5/sha1 hashes.
Try editing as follows: change
f = open(fname, "rb")
while 1:
block = f.read(1024*1024)
if not block:
break
# generate the hash
m.update(block)
f.close()


to:

f = open(fname, "rb")
nbytes = 0
while 1:
block = f.read(1024*1024)
nbytes += len(block)
if not block:
break
# generate the hash
m.update(block)
f.close()
print '%d bytes processed'

As Adam DePrince noticed, the md5 checksum you generated was that of
an empty file. So the above should tell you whether you're actually
processing any input; if you don't get the expected number of bytes,
debug from there.
Mar 26 '06 #2

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

Similar topics

1
by: Jocab | last post by:
Just had a look at the Wired.com site and it seems it's completely in XHTML and CSS. I don't understand this snippet of code on their homepage, though: <link rel="stylesheet" type="text/css"...
1
by: snowteo | last post by:
Hi,I have to do this exercises can you help me: 1)Write a program to implement exetendible hashing.If the table is small enough to fin in main memory,how does its performance compare with open and...
11
by: Wm. Scott Miller | last post by:
Hello all! We are building applications here and have hashing algorithms to secure secrets (e.g passwords) by producing one way hashes. Now, I've read alot and I've followed most of the advice...
10
by: Dino M. Buljubasic | last post by:
Hi, I am using MD5 to hash my passwords and add them to database as hashed. I have noticed though that some passwords don't get recognized and I suppose that it happen because hashing might...
19
by: Ole Nielsby | last post by:
How does the GetHashCode() of an array object behave? Does it combine the GetHashCode() of its elements, or does it create a sync block for the object? I want to use readonly arrays as...
8
by: Maya | last post by:
Hello all, I'm using MD5 hashing in my application to give unique values to huge list of items my application receives, originally every item's name was difficult to use as an id for this item...
6
by: dmcglynn | last post by:
Hello all.. I have a strange issue. I am trying to do an opendir via a UNC path, from my windows server to another windows machine. As long as my remote machine is on a physically wired...
1
by: Tinku | last post by:
Hi friends I know Static Hashing and i know about Dynamic Hashing, still i have problem to make program with Dynamic Hashing I am new in "C" world, please help me, my problem is: i have to...
11
by: January Weiner | last post by:
Hello, I need to use a hashing function for relatively short strings (roughly 16 characters or less). The data that needs to be accessed via hash is just a simple int. I just need to look up...
15
by: Vinodh | last post by:
I am reading about hashing techniques. The map data structure available in C++ STL uses hashing techniques?
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...

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.