From 36228696d50f5414a220400e524a624780ce2a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Clavijo?= Date: Mon, 12 Feb 2024 00:03:01 -0300 Subject: [PATCH] Update rot.py --- rot.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rot.py b/rot.py index c29100e..b115148 100644 --- a/rot.py +++ b/rot.py @@ -1,13 +1,15 @@ get_bin = lambda x, n: format(x, "b").zfill(n) -rol = lambda val, r_bits, max_bits: (val << r_bits % max_bits) & (2**max_bits - 1) | ( - (val & (2**max_bits - 1)) >> (max_bits - (r_bits % max_bits)) +mask = lambda max_bits: (1 << max_bits)-1 + +rol = lambda val, r_bits, max_bits: (val << r_bits % max_bits) & ((1 << max_bits) - 1) | ( + (val & ((1 << max_bits) - 1)) >> (max_bits - (r_bits % max_bits)) ) # Rotate right: 0b1001 --> 0b1100 ror = lambda val, r_bits, max_bits: ( - (val & (2**max_bits - 1)) >> r_bits % max_bits -) | (val << (max_bits - (r_bits % max_bits)) & (2**max_bits - 1)) + (val & ((1 << max_bits) - 1)) >> r_bits % max_bits +) | (val << (max_bits - (r_bits % max_bits)) & ((1 << max_bits) - 1)) max_bits = 16 # For fun, try 2, 17 or other arbitrary (positive!) values