py blowflish PY_SSIZE_T_CLEAN macro must be defined

193 views Asked by At

I'm going to receive a package with a key and I need to decrypt it with blowfish, but I'm getting this error:

SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

on this function:

def encrypt_blowfish(key, plaintext):
    cipher = Blowfish.new(key, Blowfish.MODE_ECB)
    plaintext_padded = pad_data(plaintext, 8)  # 8 é o tamanho do bloco para Blowfish
    ciphertext = cipher.encrypt(plaintext_padded)
    return ciphertext

when create blowfish

this is the code:

def pad_data(data, block_size):
    padding_len = block_size - (len(data) % block_size)
    padding = bytes([padding_len]) * padding_len
    return data + padding

def encrypt_blowfish(key, plaintext):
    cipher = Blowfish.new(key, Blowfish.MODE_ECB)
    plaintext_padded = pad_data(plaintext, 8)  # 8 é o tamanho do bloco para Blowfish
    ciphertext = cipher.encrypt(plaintext_padded)
    return ciphertext

def main():
    host = 'x.x.x.x'
    port = 2106
    login = 'x'
    senha = 'x'

    # Configurar o socket
    client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    client_socket.connect((host, port))

    # Etapa 1: Enviar RequestAuthLogin
    request_auth_login = b'\x08' + b'\x32\x00\x00' + b'\x08\x00\x00' + login.encode() + b'\x00\x00\x00\x00'
    request_auth_login = len(request_auth_login).to_bytes(2, byteorder='little') + request_auth_login
    client_socket.send(request_auth_login)
    print('Enviado RequestAuthLogin')

    # Receber e decifrar o RSA Key
    rsa_key = client_socket.recv(128)
    rsa_key_decrypted = encrypt_blowfish(b'5F3B352E5D39342D33313D3D2D257854215E5B24\x00', rsa_key)
    print('RSA Key recebida e decifrada:', rsa_key_decrypted.hex())
    client_socket.close()

if __name__ == '__main__':
    main()
0

There are 0 answers