Python Forum
how can I generate a password in hashlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how can I generate a password in hashlib
#19
And here is what you really need to do
import csv
import hashlib

# create rainbow table
rainbow_table = {}
for i in range(1000, 10000): # note you need upper end to be 10000 in odrder to include 9999
    my_hash = hashlib.sha256(str(i).encode()).hexdigest()
    rainbow_table[my_hash] = i

# read the input file
with open ('code.csv', 'r') as in_file:
    rdr=csv.reader(in_file)
    data = [[name, rainbow_table.get(my_hash, '')] for name, my_hash in rdr]

# print data to see what you've got
print(data)

with open('decoded.csv', 'w', newline='') as out_file:
        wrtr = csv.writer(out_file)
        wrtr.writerows(data)
if you don't want to process the entire file in memory before write to output file eventually you may
import csv
import hashlib

# create rainbow table
rainbow_table = {}
for i in range(1000, 10000): # note you need upper end to be 10000 in odrder to include 9999
    my_hash = hashlib.sha256(str(i).encode()).hexdigest()
    rainbow_table[my_hash] = i

# read the input file, write to output
with open ('code.csv', 'r') as in_file, open('decoded.csv', 'w', newline='') as out_file:
    rdr=csv.reader(in_file)
    wrtr = csv.writer(out_file)
    for name, my_hash in rdr:
        data = [name, rainbow_table.get(my_hash, '')]
        wrtr.writerow(data) 
likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: how can I generate a password in hashlib - by buran - May-18-2019, 05:38 PM
writing on csv file problem, python - by go127a - May-14-2019, 12:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] How to crack hash with hashlib Milan 0 1,582 Mar-09-2023, 08:25 PM
Last Post: Milan
  Python3 hashlib ogautier 1 1,652 Mar-28-2022, 04:42 AM
Last Post: snippsat
  Confusion about Hashlib Vysero 2 3,115 Jun-25-2018, 04:05 PM
Last Post: DeaD_EyE
  Using SHA3 (keccak) from Hashlib CryptoFlo 0 7,978 Mar-14-2018, 10:56 AM
Last Post: CryptoFlo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020