Программа хеширования MD5 на Python дает неправильный результат ⇐ Python
Программа хеширования MD5 на Python дает неправильный результат
I am trying to rewrite MD5 hashing algorithm from scratch, the program can give me the output, but it isn't correct if I double check with other program and the hashlib library. I would love if some expert can have a look and tell me where I got it wrong
import struct from enum import Enum from bitarray import bitarray from math import ( floor, sin, ) class MD5Buffer(Enum): A = 0x67452301 B = 0xEFCDAB89 C = 0x98BADCFE D = 0x10325476 class MD5(object): _string = None _buffers = { MD5Buffer.A: None, MD5Buffer.B: None, MD5Buffer.C: None, MD5Buffer.D: None, } @classmethod def hash(cls, string): cls._string = string preprocessed_bit_array = cls._step_2(cls._step_1()) cls._step_3() cls._step_4(preprocessed_bit_array) return cls._step_5() @classmethod def _step_1(cls): bit_array = bitarray(endian="big") bit_array.frombytes(cls._string.encode("utf-8")) bit_array.append(1) while len(bit_array) % 512 != 448: bit_array.append(0) return bitarray(bit_array, endian="little") @classmethod def _step_2(cls, step_1_result): length = (len(cls._string) * 8) % pow(2, 64) length_bit_array = bitarray(endian="little") length_bit_array.frombytes(struct.pack("
Источник: https://stackoverflow.com/questions/780 ... ong-result
I am trying to rewrite MD5 hashing algorithm from scratch, the program can give me the output, but it isn't correct if I double check with other program and the hashlib library. I would love if some expert can have a look and tell me where I got it wrong
import struct from enum import Enum from bitarray import bitarray from math import ( floor, sin, ) class MD5Buffer(Enum): A = 0x67452301 B = 0xEFCDAB89 C = 0x98BADCFE D = 0x10325476 class MD5(object): _string = None _buffers = { MD5Buffer.A: None, MD5Buffer.B: None, MD5Buffer.C: None, MD5Buffer.D: None, } @classmethod def hash(cls, string): cls._string = string preprocessed_bit_array = cls._step_2(cls._step_1()) cls._step_3() cls._step_4(preprocessed_bit_array) return cls._step_5() @classmethod def _step_1(cls): bit_array = bitarray(endian="big") bit_array.frombytes(cls._string.encode("utf-8")) bit_array.append(1) while len(bit_array) % 512 != 448: bit_array.append(0) return bitarray(bit_array, endian="little") @classmethod def _step_2(cls, step_1_result): length = (len(cls._string) * 8) % pow(2, 64) length_bit_array = bitarray(endian="little") length_bit_array.frombytes(struct.pack("
Источник: https://stackoverflow.com/questions/780 ... ong-result
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Изменение алгоритма хеширования WordPress по умолчанию с MD5 на ARGON2ID без плагина на PHP
Anonymous » » в форуме Php - 0 Ответы
- 24 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Изменение алгоритма хеширования WordPress по умолчанию с MD5 на ARGON2ID без плагина на PHP
Anonymous » » в форуме Php - 0 Ответы
- 32 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Функция хеширования md5 в php обрабатывается с разной скоростью на разных серверах [закрыто]
Anonymous » » в форуме Php - 0 Ответы
- 22 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Функция хеширования md5 в php обрабатывается с разной скоростью на разных серверах [закрыто]
Anonymous » » в форуме Php - 0 Ответы
- 17 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Функция хеширования md5 в php обрабатывается с разной скоростью на разных серверах [закрыто]
Anonymous » » в форуме Php - 0 Ответы
- 25 Просмотры
-
Последнее сообщение Anonymous
-