1616# You should have received a copy of the GNU Lesser General Public License
1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
19- from pyaes import AES
19+ # from pyaes import AES
20+ import tgcrypto
2021
2122BLOCK_SIZE = 16
2223
2627class IGE :
2728 @classmethod
2829 def encrypt (cls , data : bytes , key : bytes , iv : bytes ) -> bytes :
29- return cls .ige (data , key , iv , True )
30+ return tgcrypto .ige_encrypt (data , key , iv )
31+ # return cls.ige(data, key, iv, True)
3032
3133 @classmethod
3234 def decrypt (cls , data : bytes , key : bytes , iv : bytes ) -> bytes :
33- return cls .ige (data , key , iv , False )
35+ return tgcrypto .ige_decrypt (data , key , iv )
36+ # return cls.ige(data, key, iv, False)
3437
3538 @staticmethod
3639 def xor (a : bytes , b : bytes ) -> bytes :
@@ -40,22 +43,22 @@ def xor(a: bytes, b: bytes) -> bytes:
4043 "big" ,
4144 )
4245
43- @classmethod
44- def ige (cls , data : bytes , key : bytes , iv : bytes , encrypt : bool ) -> bytes :
45- cipher = AES (key )
46-
47- iv_1 = iv [:BLOCK_SIZE ]
48- iv_2 = iv [BLOCK_SIZE :]
49-
50- data = [data [i : i + BLOCK_SIZE ] for i in range (0 , len (data ), BLOCK_SIZE )]
51-
52- if encrypt :
53- for i , chunk in enumerate (data ):
54- iv_1 = data [i ] = cls .xor (cipher .encrypt (cls .xor (chunk , iv_1 )), iv_2 )
55- iv_2 = chunk
56- else :
57- for i , chunk in enumerate (data ):
58- iv_2 = data [i ] = cls .xor (cipher .decrypt (cls .xor (chunk , iv_2 )), iv_1 )
59- iv_1 = chunk
60-
61- return b"" .join (data )
46+ # @classmethod
47+ # def ige(cls, data: bytes, key: bytes, iv: bytes, encrypt: bool) -> bytes:
48+ # cipher = AES(key)
49+ #
50+ # iv_1 = iv[:BLOCK_SIZE]
51+ # iv_2 = iv[BLOCK_SIZE:]
52+ #
53+ # data = [data[i: i + BLOCK_SIZE] for i in range(0, len(data), BLOCK_SIZE)]
54+ #
55+ # if encrypt:
56+ # for i, chunk in enumerate(data):
57+ # iv_1 = data[i] = cls.xor(cipher.encrypt(cls.xor(chunk, iv_1)), iv_2)
58+ # iv_2 = chunk
59+ # else:
60+ # for i, chunk in enumerate(data):
61+ # iv_2 = data[i] = cls.xor(cipher.decrypt(cls.xor(chunk, iv_2)), iv_1)
62+ # iv_1 = chunk
63+ #
64+ # return b"".join(data)
0 commit comments