rust

Rust Decrypt from Python cryptography

Rust Decrypt from Python cryptography Question: I used cryptography to encrypt image file in Python. The code is here: import hashlib import base64 from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import padding import time key = "secretkey" keyBytes = hashlib.sha256(key.encode()).digest() ivBytes = b"xdaxe4x87xa7ix8arbOCxbd x02xbc*[" file_name = "1024.jpg" with open(file_name, "rb") …

Total answers: 2

Embedded a #[pyclass] in another #[pyclass]

Embedded a #[pyclass] in another #[pyclass] Question: I am trying to implement a cache for the private variable of any python class. Let’s suppose I have this: #[pyclass] struct ClassA { pv: Py<PyAny>, // GIL independent type, storable in another #[pyclass] field_a: Py<PyAny>, } #[pyclass] struct ClassB { class_a: Py<ClassA>, field_b: Py<PyAny>, } In the …

Total answers: 1

How to iterate over vector of pyclass objects in rust?

How to iterate over vector of pyclass objects in rust? Question: I am using maturin and I am trying to implement the method get_car() for my class. But using the following code use pyo3::prelude::*; #[pyclass] struct Car { name: String, } #[pyclass] struct Garage { cars: Vec<Car>, } #[pymethods] impl Garage { fn get_car(&self, name: …

Total answers: 1

Questions about Rust BigInt memory allocation and performance compared to Python BigInt implementation

Rust BigInt memory allocation and performance compared to Python BigInt implementation Question: When working with num_bigint::BigInt I have run into some performance limitations, for context I am working on https://www.geeksforgeeks.org/how-to-generate-large-prime-numbers-for-rsa-algorithm/ [full code at bottom of page]. In the nBitRand function we essentially shuffle a vector of BigInt’s determined by the range: (2.pow(n – 1) + …

Total answers: 2

Why nested When().Then() is slower than Left Join in Rust Polars?

Why nested When().Then() is slower than Left Join in Rust Polars? Question: In Rust Polars(might apply to python pandas as well) assigning values in a new column with a complex logic involving values of other columns can be achieved in two ways. The default way is using a nested WhenThen expression. Another way to achieve …

Total answers: 2

Can you write part of a library in rust (pyo3) but the rest in python?

Can you write part of a library in rust (pyo3) but the rest in python? Question: I want to write part of a python module in rust (with PYo3) but also partly in python, so something like… src/utils.rs: use pyo3::prelude::*; #[pyfunction] fn sum_as_string(a: usize, b: usize) -> PyResult<String> { Ok((a + b).to_string()) } #[pymodule] fn …

Total answers: 1

Issue installing python bcrypt in Cygwin

Issue installing python bcrypt in Cygwin Question: I’m trying to install paramiko in Cygwin and one of the build dependencies is bcrypt. I have rustc installed and I believe all of the supporting build libraries. Pip is also updated to the latest. $ pip –version pip 22.2.2 from /usr/local/lib/python3.8/site-packages/pip (python 3.8) I use the following …

Total answers: 1

Rust function as slow as its python counterpart

Rust function as slow as its python counterpart Question: I am trying to speed up Python programs using Rust, a language in which I am a total beginner. I wrote a function that counts the occurrences of each possible string of length n within a larger string. For instance, if the main string is "AAAAT" …

Total answers: 2

Idiomatic Rust index filtering (numpy style)

Idiomatic Rust index filtering (numpy style) Question: A common idiom that I use in python for initializing arrays is arr = np.zeros(10) x = np.linspace(-5,5,10) arr[np.abs(x)<2] = 1. That is, conditionally changing elements of an array using a "view". Is there an idiomatic way of doing this (also with a vector or other collection) in …

Total answers: 2