how to use AES256 ECB mode in Rust ?
- User
how to use AES256 ECB mode in Rust ?
- Assistant
- User
Nice. it works! Now consider this Python code. I need to convert it into equivalent code in Rust in same fashion -> from random import randint from Crypto.Util.number import getPrime, long_to_bytes as l2b from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad from hashlib import sha256
plaintext = b"Flag: HTB{fake_fl4g_4_test1ng}" aes_key = "" enc_secret = ""
class AESGen: def init(self, size): key1 = randint(1 << size, 1 << (size+1)) key2 = randint(1 << size, 1 << (size+1)) self.k = key1 * key2
print(key1) print(key2) print(f"k: {self.k}") assert 40 <= self.k.bit_length() <= 42 self.KEY = sha256(str(self.k).encode()).digest() print(f"SHA256 KEY: {self.KEY}") def encrypt(self, m): cipher = AES.new(self.KEY, AES.MODE_ECB) enc_secret = cipher.encrypt(pad(m, 16)) return enc_secret def decrypt(self, enc_m): cipher = AES.new(self.KEY, AES.MODE_ECB) dec_secret = unpad(cipher.decrypt(enc_m), 16) return dec_secret - Assistant
- User
--> src/main.rs:37:35 | 37 | if decrypted.contains(&b"HTB{"[..]) { | -------- ^^^^^^^^^^^^ expected
&u8, found&[u8]| | | arguments to this method are incorrect | = note: expected reference&u8found reference&[u8] - Assistant
Apologies for the oversight. The
containsmethod of aVec<u8>expects a reference to a single byte as an argument (i.e., ), not a byte slice (). Instead of using , you can use the method with to search for a subslice. Here's the corrected code: - User
Good ! Now i need to split decryption and encryption functions separetelly and call them when needed by same logic please
- Assistant
- User
- Assistant
- User
how to make this code concurrent and run on multiple cores of the CPU ??
- Assistant