MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / to_little_endian

Function to_little_endian

hashes/md5.py:18–43  ·  view source on GitHub ↗

Converts the given string to little-endian in groups of 8 chars. Arguments: string_32 {[string]} -- [32-char string] Raises: ValueError -- [input is not 32 char] Returns: 32-char little-endian string >>> to_little_endian(b'1234567890abcdfghijklmnopqrst

(string_32: bytes)

Source from the content-addressed store, hash-verified

16
17
18def to_little_endian(string_32: bytes) -> bytes:
19 """
20 Converts the given string to little-endian in groups of 8 chars.
21
22 Arguments:
23 string_32 {[string]} -- [32-char string]
24
25 Raises:
26 ValueError -- [input is not 32 char]
27
28 Returns:
29 32-char little-endian string
30 >>> to_little_endian(b'1234567890abcdfghijklmnopqrstuvw')
31 b'pqrstuvwhijklmno90abcdfg12345678'
32 >>> to_little_endian(b'1234567890')
33 Traceback (most recent call last):
34 ...
35 ValueError: Input must be of length 32
36 """
37 if len(string_32) != 32:
38 raise ValueError("Input must be of length 32")
39
40 little_endian = b""
41 for i in [3, 2, 1, 0]:
42 little_endian += string_32[8 * i : 8 * i + 8]
43 return little_endian
44
45
46def reformat_hex(i: int) -> bytes:

Callers 2

preprocessFunction · 0.85
get_block_wordsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected