Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Step-by-Step implementation of the SHA-256 algorithm in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
dec_message = []
for char in message:
dec_message.append(ord(char))
print('The decimal representation is ')
print(dec_message)
bin_message = ''
for decimal in dec_message:
bin_message += '0' + bin(decimal)[2:]
print('The binary representation is ')
print(bin_message)
len_bin_message = len(bin_message)
print('The binary representation has a length of')
print(str(len_bin_message) + ' bits aka')
print(bin(len_bin_message)[2:])
print('Extended to 64 bits:')
rest_to_64 = 64 - len(bin(len_bin_message)[2:])
bin_message_len = '0' * rest_to_64 + bin(len_bin_message)[2:]
print(bin_message_len)
payload = bin_message + '1' + bin_message_len
len_payload = len(payload)
pad_string = int(512 - (len_payload % 512))
print('Need to add %s zeros to get a multiple of 512 bits' % pad_string)
full_message = bin_message + '1' + ('0' * pad_string) + bin_message_len
print(full_message)
print('Check the length: ' + str(len(full_message)) + ' bits')
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Tardis4Future
Copy link

Tardis4Future commented Aug 5, 2022

Hello, i got message that this notebook is invalid. I can not open it in jupyter.
Thanks for your help!

Edit: now I put the lines manually in jupyter but after loop #47 i got following message:

Unbenannt

Can you fix it please? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment