diff --git a/TL.py b/TL.py index 643df50a..385764d8 100644 --- a/TL.py +++ b/TL.py @@ -3,7 +3,7 @@ import os import struct import json import io -import numbers +from numbers import Number class TlConstructor: def __init__(self, json_dict): @@ -78,10 +78,11 @@ def serialize_method(bytes_io, type_, **kwargs): def serialize_param(bytes_io, type_, value): if type_ == "int": - assert isinstance(value, int) + assert isinstance(value, Number) + assert value.bit_length() <= 32 bytes_io.write(struct.pack('>') - # vis(step2) def recv_message(self): """ @@ -111,30 +96,42 @@ class Session: """ packet_length_data = self.sock.recv(4) # reads how many bytes to read - if len(packet_length_data) > 0: # if we have smth. in the socket - packet_length = struct.unpack("q', pq_bytes)[0] [p, q] = prime.primefactors(pq) if p > q: (p, q) = (q, p) assert p*q == pq and p < q @@ -243,7 +239,6 @@ class Session: auth_key = pow(g_a, b, dh_prime) auth_key_str = long_to_bytes(auth_key) auth_key_sha = SHA.new(auth_key_str).digest() - auth_key_hash = auth_key_sha[-8:] auth_key_aux_hash = auth_key_sha[:8] new_nonce_hash1 = SHA.new(new_nonce+b'\x01'+auth_key_aux_hash).digest()[-16:] @@ -257,6 +252,7 @@ class Session: self.server_salt = strxor(new_nonce[0:8], server_nonce[0:8]) self.auth_key = auth_key_str + self.auth_key_id = auth_key_sha[-8:] print("Auth key generated") def aes_calculate(self, msg_key, direction="to server"): diff --git a/testing.py b/testing.py index 294626a8..449f335a 100644 --- a/testing.py +++ b/testing.py @@ -19,4 +19,11 @@ if not config.read('credentials'): ip = config.get('App data', 'ip_address') port = config.getint('App data', 'port') -Session = mtproto.Session(ip, port) \ No newline at end of file +Session = mtproto.Session(ip, port) +Session.create_auth_key() + +i = 0 +while True: + f = Session.method_call('ping', ping_id=i) + print(f) + i += 1 \ No newline at end of file