2020
2121log = logging .getLogger (__name__ )
2222
23+
24+ def xor (a : bytes , b : bytes ) -> bytes :
25+ return int .to_bytes (
26+ int .from_bytes (a , "big" ) ^ int .from_bytes (b , "big" ),
27+ len (a ),
28+ "big" ,
29+ )
30+
31+
2332try :
2433 import tgcrypto
2534
@@ -41,13 +50,6 @@ def ctr256_encrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = No
4150 def ctr256_decrypt (data : bytes , key : bytes , iv : bytearray , state : bytearray = None ) -> bytes :
4251 return tgcrypto .ctr256_decrypt (data , key , iv , state or bytearray (1 ))
4352
44-
45- def xor (a : bytes , b : bytes ) -> bytes :
46- return int .to_bytes (
47- int .from_bytes (a , "big" ) ^ int .from_bytes (b , "big" ),
48- len (a ),
49- "big" ,
50- )
5153except ImportError :
5254 import pyaes
5355
@@ -74,14 +76,6 @@ def ctr256_decrypt(data: bytes, key: bytes, iv: bytearray, state: bytearray = No
7476 return ctr (data , key , iv , state or bytearray (1 ))
7577
7678
77- def xor (a : bytes , b : bytes ) -> bytes :
78- return int .to_bytes (
79- int .from_bytes (a , "big" ) ^ int .from_bytes (b , "big" ),
80- len (a ),
81- "big" ,
82- )
83-
84-
8579 def ige (data : bytes , key : bytes , iv : bytes , encrypt : bool ) -> bytes :
8680 cipher = pyaes .AES (key )
8781
0 commit comments