Я работаю с приложением xorcipher для тестирования функций Python и Rust, но я не знаю, как добавить функцию Rust в код Python. Может ли кто-нибудь помочь, мне нужно сохранить выходные данные в buf, я включаю свой Rust-код
use std::convert::TryInto;
/*
Apply a simple XOR cipher using they specified `key` of size
`key_size`, to the `msg` char/byte array of size `msg_len`.
Writes he ciphertext to the externally allocated buffer `buf`.
*/
#[no_mangle]
pub unsafe fn cipher(msg: *const i8, key: *const i8, buf: *mut i8, msg_len: usize, key_len: usize)
{
let mut i: isize = 0;
while i < msg_len.try_into().unwrap() {
let key_len_i8: i8 = key_len.try_into().unwrap();
*buf.offset(i) = *msg.offset(i) ^ (*key.offset(i) % key_len_i8);
i = i + 1;
}
}