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

Function left_rotate_32

hashes/md5.py:253–294  ·  view source on GitHub ↗

Rotate the bits of a given int left by a given amount. Arguments: i {[int]} -- [given int] shift {[int]} -- [shift amount] Raises: ValueError -- [either given int or shift is negative] Returns: `i` rotated to the left by `shift` bits >>> left_

(i: int, shift: int)

Source from the content-addressed store, hash-verified

251
252
253def left_rotate_32(i: int, shift: int) -> int:
254 """
255 Rotate the bits of a given int left by a given amount.
256
257 Arguments:
258 i {[int]} -- [given int]
259 shift {[int]} -- [shift amount]
260
261 Raises:
262 ValueError -- [either given int or shift is negative]
263
264 Returns:
265 `i` rotated to the left by `shift` bits
266
267 >>> left_rotate_32(1234, 1)
268 2468
269 >>> left_rotate_32(1111, 4)
270 17776
271 >>> left_rotate_32(2147483648, 1)
272 1
273 >>> left_rotate_32(2147483648, 3)
274 4
275 >>> left_rotate_32(4294967295, 4)
276 4294967295
277 >>> left_rotate_32(1234, 0)
278 1234
279 >>> left_rotate_32(0, 0)
280 0
281 >>> left_rotate_32(-1, 0)
282 Traceback (most recent call last):
283 ...
284 ValueError: Input must be non-negative
285 >>> left_rotate_32(0, -1)
286 Traceback (most recent call last):
287 ...
288 ValueError: Shift must be non-negative
289 """
290 if i < 0:
291 raise ValueError("Input must be non-negative")
292 if shift < 0:
293 raise ValueError("Shift must be non-negative")
294 return ((i << shift) ^ (i >> (32 - shift))) % 2**32
295
296
297def md5_me(message: bytes) -> bytes:

Callers 1

md5_meFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected