Python loops works in idle but not in my programm functions

Hi ! I written this code that add b’\x01’ to an bytestring until it’s size is 24 bytes. Code :

def bytesLenght(s):
    if isinstance(s, str):
        return len(s.encode('utf-8'))
    elif isinstance(s, bytes):
        return len(s)
byteslenght = bytesLenght

def total24bytes(key):
    ke = key.encode()
    while byteslenght(ke) != 24:
            ke += b'\x01'
    return ke

When i run the function in IDLE directly, it’s okay (output) :
But when i run it into a function (called add) into the programm, and i launch the function, it never stop…

Whats wrong ? Repl adress : pls help - Python Repl - Replit

I expect key is longer then 24 bytes.

Tip: when dealing with lengths use > or < instead of == or !=.
That way an unexpected long key would not loop forever.

In your example you can use <= 24