Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

md5 shit in python

Name: Anonymous 2009-01-20 23:22

import os, md5;

for root, dirs, files in os.walk(os.path.abspath('')):
    for f in files:
        e = os.path.splitext(f)[1]
        if (e and e not in [".py",".db"]):
            h = md5.new(file(f,'rb').read()).hexdigest()
            n = h + e
            try:
                os.rename(f,n)
            except WindowsError:
                os.unlink(n)
                os.rename(f,n)
            print n + " " + f


How do I optimize this, I'm watching SICP right now

Name: Anonymous 2009-01-20 23:36

MD5 IS DEPRECATEED USE HASHLIB INSTEAD BITCH
but srsly python is just slow in general and you can't really optimize further

Name: Anonymous 2009-01-20 23:51

>>2
Please don't make troll posts!

Name: Anonymous 2009-01-21 0:18

Name: Anonymous 2009-01-21 8:14

Use SHA-1.

Name: Anonymous 2009-01-21 10:07

If you're working with files of any significant size, reading them in chunks will speed things up, save memory, and increase your number of lines of code, thus providing job security.

shit = hashlib.md5()
bitch = file(whatever, 'rb')
fuck = 'nigger'
while fuck:
    fuck = bitch.read(4096) # whatever. look up the size of your disk blocks, make it a multiple of that
    shit.update(fuck)
dick = shit.hexdigest()


But really, the speed of this code is pretty much entirely dependent on the implementation of your hashing algorithm and the speed of your disk, and since an md5 isn't thoroughly processor intensive, the speed of even a modest implementation will surpass typical disk read speeds. You can tell where the major bottleneck lies by comparing the processor load and disk activity graphs in a performance monitoring tool; I'd be almost certain that, for your code, you will be spending more time waiting for I/O than actually computing anything, and only a tiny fraction of that is in the Python interpreter.

... oh, fuck, I just accidentally started writing a serious answer. Sorry.

REWRITE YOUR CODE IN LISP

Name: Anonymous 2009-01-21 10:18

>>6
because the operating system won't implement any form of read caching

Name: Anonymous 2009-01-21 12:01

>>1
What part of that is bottlenecking?

HINT: It's probably your disk.

Name: Anonymous 2009-01-21 13:44

HINT: THE FORCED INDENTATION OF CODE

Name: Anonymous 2009-01-21 18:05

>>9 is right. It's clearly slow because the interpreter has to seek past all those spaces and tabs.

Name: Anonymous 2009-01-21 18:44

>>10
yeah, theyre the worst characters. that's why binaries don't indentation.

Name: Anonymous 2009-01-21 18:46

def _raise(e): raise e
class chunk(object):
    __init__ = lambda s, fp: setattr(s, 'fp', fp)
    __iter__ = lambda s: s
    next     = lambda s: s.fp.read(4096) or _raise(StopIteration)

hash = __import__('hashlib').sha512()
map(hash.update, chunk(open('latex.7z', 'rb')))
print hash.hexdigest()

Name: Anonymous 2009-01-21 18:54

# For reduced memory usage.
reduce(lambda *z: [hash.update(i) for i in z if i] and None, chunk(open('latex.7z', 'rb')))

Name: Anonymous 2009-01-21 19:10

>>11
nop

Name: Anonymous 2009-01-21 22:35

>>14
fnop is superior

Name: Anonymous 2009-01-22 0:01

>>14
xchg eax,eax ( nop is an alias to that for x86, try assembling it )

Name: Anonymous 2009-01-22 0:17

>>16
and that is why fnop is superior

Name: Anonymous 2009-01-22 2:21

>>17
However there is a minor problem with fnop, it takes two bytes as opposed to one ( 0xD9 0xD0 for fnop, and 0x90 for nop), so if you had random piece of code/function which you wanted to nop, you couldn't just memset it to a nop buffer. Yes, that can be solved by just filling it with D9D0 for len/2 and if len%2==1 then fill that byte with a nop. This creates another problem: filler nop buffers you want to jump to: if you jump randomly in the buffer and land on a D0D9 instead of a D9D0, it'll execute a rcr cl,1 ( until the buffer ends ). A similar problem/situation is encountered with int3(CC) alignment buffers for debug builds of apps. You usually have to use int3 since the length is 1, however, a less common choice is to use "int 0CD" (which assembles to 0xCD 0xCD , meaning if you jumped into the buffer, you'll still execute the interrupt which will trigger the exception handler)

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-22 4:45

fnop/nop is superfluous for large chunks of code.
use LEA [next executable code address]

_________________________
orbis terrarum delenda est
 http://xs135.xs.to/xs135/09042/av922.jpg

Name: Anonymous 2009-01-22 6:46

fnop mouse + you = fnop mouse

Name: Anonymous 2009-01-22 6:59

The point was that nop indents machine code.

>>15,17,19
/r/ benchmarks.

Name: Anonymous 2009-01-22 7:19

>>19
You have clearly no idea what you're talking about. Not that there is much of a topic to talk about, nop has its purposes, and if you just want to skip a large chunk of code you'd just assemble an unconditional long jump.

FUCK, I SHOULDN'T READ YOUR POSTS. IHBT

Name: Anonymous 2009-01-22 7:35

>>22
DOWNLOAD THE GREASEMONKEY SCRIPT! HELP SAVE /prog/!

Name: FrozenVoidFan 2009-01-22 8:29

>>23
STOP IGNORING FV! GIVE IN TO HIS POWER!

Name: Anonymous 2009-01-22 8:50

>>24
He proposed using lea as a nop, which I guess could work for lea eax, [eax], but is SLOW AS FUCK

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-22 9:23

>>25
What is faster: 100000 NOPs or LEA [next executable address]?

_________________________
orbis terrarum delenda est
 http://xs135.xs.to/xs135/09042/av922.jpg

Name: Anonymous 2009-01-22 10:09

>>26
They don't do the same thing, so comparing their speed would be useless. Lea doesn't move the instruction pointer.

But if you insist, nop has a latency of 1/3 while I would guess lea has at least 4, depending on the memory address.

Ergo, to move the eip 100000 bytes, 100000 nops would take 33333 cycles and 16666 leas would take 66666.

And using fnop instead of nop halves the needed cycles, being 4 times faster than lea, so you are utterly wrong.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-22 10:19

>>27
You only need one LEA instead of 16666 leas .

_________________________
orbis terrarum delenda est
 http://xs135.xs.to/xs135/09042/av922.jpg

Name: Anonymous 2009-01-22 10:31

Who the fuck are you guys talking to?

Name: Anonymous 2009-01-22 10:37

LEA IS NOT A JUMP YOU IDIOT.

Yes you can treat it as a nop when using "LEA REG,DWORD PTR:[REG]" and all it will do is reg:=reg which is effectively a no-op.

LEA is similar to a mov instruction, which tends to be used to manipulate offsets oftenly(for example to take the address of an element in an array), thus its name. It is not an instruction for changing the instruction pointer(IP/EIP).

Fucking read your manuals.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-22 10:46

>>30
"It is not an instruction for changing the instruction pointer(IP/EIP)."
Linux kernel sources say otherwise.
http://oldlinux.org/lxr/http/source/kernel/sys_call.S?v=0.97
_________________________
orbis terrarum delenda est
 http://xs135.xs.to/xs135/09042/av922.jpg

Name: Anonymous 2009-01-22 11:00

>>31
THE INSTRUCTION LEA DOES NOT CHANGE EIP BY ITSELF( EIP is incremented by instruction size, but so is true for most instructions which don't operate on eip (jumps,return,calls))

In the code you posted, there are 2 instances of using LEA:
    lea (EIP+4)(%esp),%eax  # don't forget about the return address.
    lea 52(%esp),%edx

In the second case it's just assigns edx with an address on the stack, so I'll assume that's not what you're talking about.
In the first case EIP+4 is actually a macro for a variable on the stack 
EIP             = 0x30

so it's nothing more than lea eax, dword ptr [esp+34h] no changing EIP there. The lea instruction cannot change EIP directly. What that example does is modify the context. The instruction which actually changes eip in that code is iret

FUCK OFF PLEASE

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-22 11:07

>>32
If you don't like lea changing your EIP
 just use iret then.

_________________________
orbis terrarum delenda est
 http://xs135.xs.to/xs135/09042/av922.jpg

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-22 11:22

Both are faster then executing series of NOPs.
Just some prefer to use NOPs.

_________________________
orbis terrarum delenda est
 http://xs135.xs.to/xs135/09042/av922.jpg

Name: Anonymous 2009-01-22 11:34

Do you realize that iret is an instruction which only works in ring 0 (kernel mode). Anyway, please read your x86 assembly books before talking about this.

Now to get that damn greasemonkey script which fixes /prog/ working on my copy of Opera.

Name: Anonymous 2009-01-22 11:47

BLISS

Name: Anonymous 2009-01-22 11:49

>>35
iret ... only works in ring 0
Bullshit.

Name: Anonymous 2009-01-22 11:52

>>37
It'll usually generate an exception in ring3. It works in real mode.

Name: Anonymous 2009-01-22 11:56

also depends on eflags for virtual 8086 mode...

Name: Anonymous 2009-01-22 12:09

>>38
Bullshit.

Name: Anonymous 2009-03-06 6:49

' a function or   procedure The shot   has float s   on the second   I knew older   architectures had 9   or 18 bit   columns in memory   and such wasting!

Name: Anonymous 2009-03-06 6:49

NECRO POSTING IS FAGGOTS

Name: 4CHAN IS 4 CHINKS 2010-07-28 15:42

FUCK ALL YOU CHINKS

Name: Anonymous 2010-07-28 17:13

prog/1232511435: The story of how one mere >>15 managed to derail an entire thread for two-thirds of its duration.

Don't change these.
Name: Email:
Entire Thread Thread List