mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-05 04:30:22 +03:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
2e8e314030
|
@ -127,6 +127,11 @@ There you'll find a list of all the methods, types and available constructors.
|
|||
|
||||
More examples are also available under the ``telethon_examples/`` folder.
|
||||
|
||||
If you're using Telethon under ARM, you may want to install ``sympy`` through
|
||||
``pip`` for a substantial speed-up when generating the keys required to
|
||||
connect to Telegram (you can of course do this on desktop too). See
|
||||
`issue #199 <https://github.com/LonamiWebs/Telethon/issues/199>`_ for more.
|
||||
|
||||
Common errors
|
||||
-------------
|
||||
|
||||
|
|
|
@ -5,7 +5,9 @@ import pyaes
|
|||
class AES:
|
||||
@staticmethod
|
||||
def decrypt_ige(cipher_text, key, iv):
|
||||
"""Decrypts the given text in 16-bytes blocks by using the given key and 32-bytes initialization vector"""
|
||||
"""Decrypts the given text in 16-bytes blocks by using the
|
||||
given key and 32-bytes initialization vector
|
||||
"""
|
||||
iv1 = iv[:len(iv) // 2]
|
||||
iv2 = iv[len(iv) // 2:]
|
||||
|
||||
|
@ -17,8 +19,8 @@ class AES:
|
|||
cipher_text_block = [0] * 16
|
||||
for block_index in range(blocks_count):
|
||||
for i in range(16):
|
||||
cipher_text_block[i] = cipher_text[block_index * 16 + i] ^ iv2[
|
||||
i]
|
||||
cipher_text_block[i] = \
|
||||
cipher_text[block_index * 16 + i] ^ iv2[i]
|
||||
|
||||
plain_text_block = aes.decrypt(cipher_text_block)
|
||||
|
||||
|
@ -26,17 +28,19 @@ class AES:
|
|||
plain_text_block[i] ^= iv1[i]
|
||||
|
||||
iv1 = cipher_text[block_index * 16:block_index * 16 + 16]
|
||||
iv2 = plain_text_block[:]
|
||||
iv2 = plain_text_block
|
||||
|
||||
plain_text.extend(plain_text_block[:])
|
||||
plain_text.extend(plain_text_block)
|
||||
|
||||
return bytes(plain_text)
|
||||
|
||||
@staticmethod
|
||||
def encrypt_ige(plain_text, key, iv):
|
||||
"""Encrypts the given text in 16-bytes blocks by using the given key and 32-bytes initialization vector"""
|
||||
"""Encrypts the given text in 16-bytes blocks by using the
|
||||
given key and 32-bytes initialization vector
|
||||
"""
|
||||
|
||||
# Add random padding if and only if it's not evenly divisible by 16 already
|
||||
# Add random padding iff it's not evenly divisible by 16 already
|
||||
if len(plain_text) % 16 != 0:
|
||||
padding_count = 16 - len(plain_text) % 16
|
||||
plain_text += os.urandom(padding_count)
|
||||
|
@ -50,8 +54,9 @@ class AES:
|
|||
blocks_count = len(plain_text) // 16
|
||||
|
||||
for block_index in range(blocks_count):
|
||||
plain_text_block = list(plain_text[block_index * 16:block_index *
|
||||
16 + 16])
|
||||
plain_text_block = list(
|
||||
plain_text[block_index * 16:block_index * 16 + 16]
|
||||
)
|
||||
for i in range(16):
|
||||
plain_text_block[i] ^= iv1[i]
|
||||
|
||||
|
@ -60,9 +65,9 @@ class AES:
|
|||
for i in range(16):
|
||||
cipher_text_block[i] ^= iv2[i]
|
||||
|
||||
iv1 = cipher_text_block[:]
|
||||
iv1 = cipher_text_block
|
||||
iv2 = plain_text[block_index * 16:block_index * 16 + 16]
|
||||
|
||||
cipher_text.extend(cipher_text_block[:])
|
||||
cipher_text.extend(cipher_text_block)
|
||||
|
||||
return bytes(cipher_text)
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
from random import randint
|
||||
try:
|
||||
import sympy.ntheory
|
||||
except ImportError:
|
||||
sympy = None
|
||||
|
||||
|
||||
class Factorization:
|
||||
|
@ -58,5 +62,8 @@ class Factorization:
|
|||
@staticmethod
|
||||
def factorize(pq):
|
||||
"""Factorizes the given number and returns both the divisor and the number divided by the divisor"""
|
||||
divisor = Factorization.find_small_multiplier_lopatin(pq)
|
||||
return divisor, pq // divisor
|
||||
if sympy:
|
||||
return tuple(sympy.ntheory.factorint(pq).keys())
|
||||
else:
|
||||
divisor = Factorization.find_small_multiplier_lopatin(pq)
|
||||
return divisor, pq // divisor
|
||||
|
|
Loading…
Reference in New Issue
Block a user