Hi, I can't seem to figure this out. Here's my objective: I have a value that is an md5 hash and I have a wordlist. I need to md5 the words in the list, then compare them to the given hash, then have the actual word print out. So I figured out how to take the list and md5 the words and get them to print out. Now I need to compare them but when I do this, it's only saving the very last word that was hashed. Here are some things I've tried: -
import hashlib,string
-
# the given hash, which is actually "12345"
-
x="827ccb0eea8a706c4c34a16891f84e7b"
-
f=open("words.txt","r")
-
words = f.readlines()
-
# my loop to run through the words, converting to md5
-
for word in words:
-
m=hashlib.md5(word)
-
k=m.hexdigest()
-
print k
-
That will successfully print out all of the converted values in the wordlist but now I need to compare it to 'x'. -
import hashlib,string
-
# the given hash, which is actually "12345"
-
x="827ccb0eea8a706c4c34a16891f84e7b"
-
f=open("words.txt","r")
-
words = f.readlines()
-
# my loop to run through the words, converting to md5
-
for word in words:
-
m=hashlib.md5(word)
-
k=m.hexdigest()
-
# this part only works if the value of 'x' is the very-
-
# last word in the list:
-
if k==x:
-
print "Yes!"
-
Since it's only using the very last value of 'k' I thought I'd try to save all of the converted values to a text file, then open that up and use another 'for' statement: -
import hashlib,string
-
# the given hash, which is actually "12345"
-
x="827ccb0eea8a706c4c34a16891f84e7b"
-
f=open("words.txt","r")
-
words = f.readlines()
-
# my loop to run through the words, converting to md5
-
for word in words:
-
m=hashlib.md5(word)
-
k=m.hexdigest()
-
infile=open("data.txt","w")
-
out.write(str(k))
-
out.close()
-
infile=open("data.txt","r")
-
lines=infile.readlines()
-
for line in lines:
-
if line == x:
-
print "Item found!"
-
I don't really think it's necessary for me to have to save the values first but even when I try that route it only saves and writes the very last 'k' value, not all of them. So my question is:
How can I get the value of 'x' to compare to every value of 'k'?
9 2521 bvdet 2,851
Expert Mod 2GB
Why not save the hashed words in a list? Then execute a separate for loop on the list, comparing each hash to "x".
:) Thanks, didn't think about that! This works: -
import hashlib,string
-
# the given hash, which is actually "12345"
-
x="827ccb0eea8a706c4c34a16891f84e7b"
-
f=open("words.txt","r")
-
words = f.readlines()
-
# my loop to run through the words, converting to md5
-
for word in words:
-
m=hashlib.md5(word)
-
k=m.hexdigest()
-
numbs=[k]
-
for num in numbs:
-
if num==x:
-
print "Yes!"
-
bvdet 2,851
Expert Mod 2GB
I was thinking of something like this: -
x="827ccb0eea8a706c4c34a16891f84e7b"
-
hashed_words = []
-
for word in words:
-
m=hashlib.md5(word)
-
hashed_words.append(m.hexdigest())
-
-
for i, item in hashed_words:
-
if item == x:
-
print "Line number %s matches" % (i+1)
When I try that method I get this error:
for i, item in hashed_words:
ValueError: too many values to unpack
bvdet 2,851
Expert Mod 2GB
Oops! I meant: - for i, item in enumerate(hashed_words):
After some more testing I've discovered another problem. It seems that the hashes aren't correct because the newline char is being added to the words in the list. Trying .replace or .split gives an error message there's no attribute of those for a list. Here is a wordlist with there actual md5 hashes:
12345 = 827ccb0eea8a706c4c34a16891f84e7b
apple = 1f3870be274f6c49b3e31a0c6728957f
boris = 4dbf44c6b1be736ee92ef90090452fc2
dorothy = c5483d8bfb22e65a48099ac0075ed64b
If I add a 'print words' line in the code I get:
['12345\n', 'apple\n', 'boris\n', 'dorothy']
So the last word prints out the actual hash because it doesn't have a '\n' but the rest are including it in the hash. How can I remove that char from a list?
bvdet 2,851
Expert Mod 2GB - for word in words:
-
m=hashlib.md5(word.strip())
That works the way I need it! Thank you.
Hi
I noticed that in your original post, your second bit of code had the following: - # for word in words:
-
# m=hashlib.md5(word)
-
# k=m.hexdigest()
-
# # this part only works if the value of 'x' is the very-
-
# # last word in the list:
-
# if k==x:
-
# print "Yes!"
These last two lines are not indented to the same level. Could this be the reason it only compared with the last value!?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jorgen Gustafsson |
last post by:
Hi,
im trying to write a small progam to compare data in 2 textfiles.
I want to search for values that doesnt exist in File2.
The result should be "3" in the example below but Im not
able to do...
|
by: twdo |
last post by:
Let me see if I can explain my situation clearly.
I have a table with the columns:
answer_id, question_id, member_id, answer
- answer_id is the primary key for the table.
- question_id...
|
by: William Krick |
last post by:
I'm currently evaluating two implementations of a case insensitive
string comparison function to replace the non-ANSI stricmp(). Both of
the implementations below seem to work fine but I'm...
|
by: Manny Chohan |
last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30
AM. How can i compare dates .net c# or if there is any other way such as
Javascript.
Thanks
Manny
|
by: Dennis |
last post by:
I have a public variable in a class of type color declared as follows:
public mycolor as color = color.Empty
I want to check to see if the user has specified a color like;
if mycolor =...
|
by: darrel |
last post by:
I have two comma delimted strings that I need to compare individual values
between the two. I assume the solution is likely to put them into an array?
If so, do I need to loop through one,...
|
by: John McMonagle |
last post by:
Say I have a dictionary like below:
d = {(100,500):, (100,501):, (100,502):}
Say I want to multiply all the values of the dictionary by 2:
for key in d.keys():
d = map(lambda x: x*2,...
|
by: Kermit Piper |
last post by:
Hello,
I am comparing two date values, one from a database and one that has
been converted from a hard-coded string into an actual Date type. So
far so good. The problem I'm having is that one...
|
by: Pugi! |
last post by:
hi,
I am using this code for checking wether a value (form input) is an
integer and wether it is smaller than a given maximum and greater then
a given minimum value:
function...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |