0

I wrote a program that hash the number 1 to 9999 and puts it in the "key number", then opens a CSV file and returns the hashed numbers hashed the "key number" dictionary.

    import csv
from hashlib import sha256 
key_num = {}
for num in range(1,10000): 
    d = sha256(b'%i'% num).hexdigest()
    key_num[d] = num
with open('D:/iliya/users password.csv') as f:
    r = csv.reader(f)
    for row in r :
        name = row[0]
        for grade in row[1:]:
            key = grade
            print(name,key_num[key])

Why does "b" appear in "sha256 (b '% i'% num) .hexdigest ()"?

  • Check out this answer: https://stackoverflow.com/questions/6269765/what-does-the-b-character-do-in-front-of-a-string-literal#:~:text=A%20prefix%20of%20'b'%20or,is%20automatically%20converted%20with%202to3).&text=Bytes%20literals%20are%20always%20prefixed,instead%20of%20the%20str%20type. – Sam Jun 15 '20 at 02:31
  • Please close your question as a duplicate, and read the answer I linked above. – Sam Jun 15 '20 at 02:32
  • @Sam Instead of leaving a comment, please click the "flag" button under the post to recommend closing it as a duplicate. – wjandrea Jun 15 '20 at 02:43
  • I was giving the OP the chance to do so on his/her own. – Sam Jun 15 '20 at 02:44
  • `sha256` says "optionally initialized with a string". It should be clearer, it expects a bytestring. That's what the `b` produces. – hpaulj Jun 15 '20 at 04:04

0 Answers0