473,792 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is anybody knows about a linkable, quick MD5/SHA1 calculator library ?

Hi !

I need to speedup my MD5/SHA1 calculator app that working on
filesystem's files.
I use the Python standard modules, but I think that it can be faster if
I use C, or other module for it.

I use FSUM before, but I got problems, because I "move" into "DOS area",
and the parameterizing of outer process maked me very angry (not working).
You will see this in this place:
http://mail.python.org/pipermail/pyt...ay/004697.html

So: I must handle unicode filenames. I think that if I find a library
that can working with py's unicode chars, and I can load and use it to
hash files, the code be better, and faster.

Anybody knows about same code ?

Py2.4, Windows, Py2Exe, wxPy... That was the specification.

Thanx for help:
dd
May 29 '06 #1
3 2705
On 30/05/2006 2:57 AM, DurumDara wrote:
Hi !

I need to speedup my MD5/SHA1 calculator app that working on
filesystem's files.
I use the Python standard modules, but I think that it can be faster if
I use C, or other module for it.

I use FSUM before, but I got problems, because I "move" into "DOS area",
and the parameterizing of outer process maked me very angry (not working).
You will see this in this place:
http://mail.python.org/pipermail/pyt...ay/004697.html

So: I must handle unicode filenames. I think that if I find a library
that can working with py's unicode chars, and I can load and use it to
hash files, the code be better, and faster.

Anybody knows about same code ?

Py2.4, Windows, Py2Exe, wxPy... That was the specification.


Hello (again), dd ...

As the effbot has said, the Python md5 and sha modules are written in C.
Hints: (1) the helpfile index says "builtin module" (2) you don't find a
sha.py or md5.py in c:\Python24\Lib \

An md5/sha library will concern itself with strings (which you obtain
from a file's *contents*), just like Python's modules do. Any struggle
with Unicode characters in the *names* of files is a separate concern.

Let's all stop worrying about low-level things like getting the 8.3
filename so that you can pass it to an MS-DOS program, and let's try to
explore why you think there is a problem with your initial approach.

At the end of this posting is a very simple Python function that
calculates the hash of a file (and its length), given the name of the
file (str or unicode, doesn't matter), which hashing module to use, and
a blocksize to use when reading. There is a really flash :-) user
interface that allows you to try it with either a glob pattern "*.txt",
or (as glob doesn't grok Windows mbcs/unicode filenames) a single
utf8-encoded filename.

Please try it out. My expectation is that, with a suitable choice of
blocksize, you will not be able to find anything that is significantly
faster and won't be difficult to interface to (like the FSUM program!).
If you have any problems or more questions, please don't hesitate to ask.

HTH,
John

=== function and driver ===
C:\junk>type hashtestbed.py

def hash_of_file(ha sh_module, fname, block_size):
f = open(fname, 'rb')
hashobj = hash_module.new ()
filesize = 0
while True:
block = f.read(block_si ze)
if not block: break
filesize += len(block)
hashobj.update( block)
f.close()
return (filesize, hashobj.digest( ))

def to_hex(s):
return ''.join('%02x' % ord(c) for c in s)

if __name__ == "__main__":
import sha, md5, time, sys, glob
# print sys.argv
mdlname = sys.argv[1]
mdl = {'sha': sha, 'md5': md5}[mdlname]
szs = sys.argv[2].lower()
factor = {'m': 1024*1024, 'k': 1024}.get(szs[-1], 1)
if factor == 1:
bsz = int(szs)
else:
bsz = int(szs[:-1]) * factor
filearg = sys.argv[3]
if filearg.startsw ith("'"):
# repr(single filename, encoded in utf8)
filenames = [eval(filearg).d ecode('utf8')]
# print filenames
else:
filenames = glob.glob(sys.a rgv[3])
# I'm entering the above for the "Best UI of the Year" award :-)
for fn in filenames:
t0 = time.time()
fsz, digest = hash_of_file(md l, fn, bsz)
seconds = time.time() - t0
print "%s, %r, bksz %d: %d bytes," \
" %.2f secs (%.4f secs/MB)\n\thash = %s" \
% (mdlname, fn, bsz, fsz,
seconds, seconds/fsz*1024*1024, to_hex(digest))

C:\junk>

=== sample usage ===

C:\junk>hashtes tbed.py md5 32k '\xe5\xbc\xa0\x e6\x95\x8f.txt'
md5, u'\u5f20\u654f. txt', bksz 32768: 17 bytes, 0.00 secs (0.0000 secs/MB)
hash = 746d09316053689 89a20691a906a67 f8

C:\junk>hashtes tbed.py md5 32k \downloads\pyth on*.msi
md5, '\\downloads\\p ython-2.4.2.msi', bksz 32768: 9671168 bytes, 0.08
secs (0.00
86 secs/MB)
hash = bfb6fc0704d225c 7a86d4ba8c922c7 f5
md5, '\\downloads\\p ython-2.4.3.msi', bksz 32768: 9688576 bytes, 0.06
secs (0.00
67 secs/MB)
hash = ab946459d7cfba4 a8500f9ff8d35cc 97
md5, '\\downloads\\p ython-2.5a2.msi', bksz 32768: 10274816 bytes, 0.05
secs (0.0
048 secs/MB)
hash = cedc1e1fed9c4cd 137921a80485bf0 07

=== end ===
May 30 '06 #2
DurumDara wrote:
Hi !

I need to speedup my MD5/SHA1 calculator app that working on
filesystem's files.


You could try using threads. This would allow the CPU and the disk to
work in parallel.

The sha/md5 modules don't seem to release the global interpreter lock,
so you won't be able to use multiple CPUs/cores yet.

Daniel
May 30 '06 #3
DurumDara wrote:
Hi !

I need to speedup my MD5/SHA1 calculator app that working on
filesystem's files.
I use the Python standard modules, but I think that it can be faster if
I use C, or other module for it.

I use FSUM before, but I got problems, because I "move" into "DOS area",
and the parameterizing of outer process maked me very angry (not working).
You will see this in this place:
http://mail.python.org/pipermail/pyt...ay/004697.html


FWIW I looked at what is the problem, apparently fsum converts the name
back to unicode, tries to print it and silently corrupts the output.
You give it short name XA02BB~1 of the file xAÿ and fsum prints xA

Use python module or try another utility.

May 30 '06 #4

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

Similar topics

3
3319
by: Saïd | last post by:
Hi, Is there a pure C library that emulate a calculator (with +-/* operations, plus log, sin,cos... functions). I would like to call such a program in a way resembling this: result("(4+6)*sin(pi/3)"); Or if the calculator is a reverse polish one result("4 6 + pi 3 / sin *");
24
6342
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to have on his site, a Javascript Calculator for working out the cost of what they want, for example: 1 widget and 2 widglets = £5.00
0
10430
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9033
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.