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)
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
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs