2

In the file .py I use the function:

def xor(block: int, key: int) -> int:
    return block ^ key

To which 128-bit numbers are transmitted.

I want to replace it with a function implemented in Cython. But I can't figure out how to use 128-bit numbers there

I wrote the code:

.pyx

import cython

cdef extern from *:
    ctypedef int int128 "__int128_t"

cpdef int128 xor(int128 block, int128 key):
    return block ^ key

setup.py

from distutils.core import setup
from Cython.Build import cythonize

setup(ext_modules=cythonize('C_code.pyx', language_level="3"))

however, errors occur during compilation.

Simon
  • 21
  • 1
  • Which errors do you get exactly? When I try your code (with Cython-0.29.34 and and x86_64-linux-gnu-gcc 11.3.0 as C compiler) the code compiles and runs without problems. – Marijn May 17 '23 at 20:12
  • indeed, using the gcc compiler, it was possible to compile the file, however, after importing this function into a file.py and an attempt to pass a 128-bit number to it, an error occurs: cpdef int128 xor(int128 block, int128 key): Overflow error: int is too big to convert @Marijn – Simon May 18 '23 at 22:02

0 Answers0