After reading this question/answer I thought I'd try and implement the SHA-256 for my own education. My initial thought for converting the input into a number was to use a line of code like sum([ord(character) for character in input_string])
, I quickly realized this is a terrible idea because I'm greatly reducing the entropy of the input by mapping a lot of highly varied strings to a relatively small number of integers. My second though was to get a hex representation of the string then get the base 16 integer representation of that hex string
import binascii
input_integer = int(binascii.hexlify('hello world'), 16)
However since I'm not an expert in hashing algorithms there may be something wrong with my second implementation that I'm not aware of.
How do you convert a string to a number to be used in a hash algorithm?
My code is written in python, for reference