diff --git a/mtproto.py b/mtproto.py index 8a7ad246..2e4e1c65 100644 --- a/mtproto.py +++ b/mtproto.py @@ -3,20 +3,26 @@ Created on Tue Sep 2 19:26:15 2014 @author: agrigoryev +@author: Sammy Pfeiffer """ -from binascii import crc32 +from binascii import crc32 as originalcrc32 +def crc32(data): + return originalcrc32(data) & 0xffffffff from datetime import datetime +from time import time import io import json import socket import struct + def vis(bs): """ Function to visualize byte streams. Split into bytes, print to console. :param bs: BYTE STRING """ + bs = bytearray(bs) symbols_in_one_line = 8 n = len(bs) // symbols_in_one_line for i in range(n): @@ -108,12 +114,14 @@ def serialize_param(bytes_io, type_, value): elif type_ == 'string' or 'bytes': l = len(value) if l < 254: # short string format - bytes_io.write(int.to_bytes(l, 1, 'little')) # 1 byte of string + bytes_io.write(struct.pack('q', PQ_bytes)[0] [p, q] = prime.primefactors(PQ) if p > q: (p, q) = (q, p) assert p*q == PQ and p < q print("PQ = %d\np = %d, q = %d" % (PQ, p, q)) - -P_bytes = int.to_bytes(p, p.bit_length()//8+1, 'big') -Q_bytes = int.to_bytes(q, q.bit_length()//8+1, 'big') +P_bytes = struct.pack('>i', p) +Q_bytes = struct.pack('>i', q) +# print("p.bit_length()//8+1: " + str(p.bit_length()//8+1)) # 4 +# print("q.bit_length()//8+1: " + str(q.bit_length()//8+1)) # 4 +# P_bytes = int.to_bytes(p, p.bit_length()//8+1, 'big') +# Q_bytes = int.to_bytes(q, q.bit_length()//8+1, 'big') f = open('rsa.pub', 'r') key = RSA.importKey(f.read())