好的,所以我尝试创建一个脚本来执行以下操作:在一个目录中搜索已知的哈希值。这是我的第一个剧本:
在哈希.py在
import hashlib
from functools import partial
#call another python script
execfile("knownHashes.py")
def md5sum(filename):
with open(filename, mode='rb') as f:
d = hashlib.md5()
for buf in iter(partial(f.read, 128), b''):
d.update(buf)
return d.hexdigest()
print "Hash of is: "
print(md5sum('photo.jpg'))
if md5List == md5sum:
print "Match"
在knownHashes.py在
^{pr2}$现在的问题是,我必须手动输入文件,我想知道它在哪里显示的哈希值照片.jpg. 另外,我还没有得到md5列表工作。在
我希望剧本最终能这样运作:
python hash.py <directory>
1 match
cookies.jpg matches hash
那么如何让脚本搜索目录而不是手动键入要散列的文件呢?另外,我如何修复md5List,因为这是错误的?在
可以使用以下命令获取当前工作目录中的文件列表。从这个目录运行这个脚本。在
可以使用for循环遍历列表:
^{pr2}$正如下面提到的春分点,也可以使用^{} 。在
简单的小要点可以解决你的大部分问题。如果你不喜欢使用OOP来解决这个问题,这是可以理解的,但是我相信所有重要的概念部分都是以一种非常简洁的方式呈现的。如果你有任何问题请告诉我。在
相关问题 更多 >
编程相关推荐