'bebebe'
This commit is contained in:
parent
d515a0b181
commit
fdb5a6bfdc
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
BIN
__pycache__/module G.cpython-312-pytest-7.4.4.pyc
Normal file
BIN
__pycache__/module G.cpython-312-pytest-7.4.4.pyc
Normal file
Binary file not shown.
68
module G.py
68
module G.py
@ -9,35 +9,45 @@ import json
|
|||||||
KEY = b'8888888888888888'
|
KEY = b'8888888888888888'
|
||||||
IV_LENGTH = 16
|
IV_LENGTH = 16
|
||||||
|
|
||||||
async def decrypt_message(encrypted_message):
|
async def test_client():
|
||||||
# Декодируем base64
|
uri = "wss://ws.bitmex.com/realtime" # вместо этой строки будет строка с хостом и портом от сервера Дмитрия Андреевича
|
||||||
encrypted_data = base64.b64decode(encrypted_message)
|
|
||||||
|
|
||||||
# Извлекаем IV и зашифрованный текст
|
|
||||||
iv = encrypted_data[:IV_LENGTH]
|
|
||||||
cipher_text = encrypted_data[IV_LENGTH:]
|
|
||||||
|
|
||||||
# Создаем объект Cipher для расшифровки
|
|
||||||
cipher = Cipher(algorithms.AES(KEY), modes.CBC(iv), backend=default_backend())
|
|
||||||
decryptor = cipher.decryptor()
|
|
||||||
|
|
||||||
# Расшифровываем данные
|
|
||||||
decrypted_data = decryptor.update(cipher_text) + decryptor.finalize()
|
|
||||||
|
|
||||||
# Удаляем PKCS5Padding
|
|
||||||
padding_length = decrypted_data[-1]
|
|
||||||
decrypted_data = decrypted_data[:-padding_length]
|
|
||||||
|
|
||||||
return decrypted_data.decode('utf-8')
|
|
||||||
|
|
||||||
async def listen():
|
|
||||||
uri = "ws://45.67.56.214:8088/users"
|
|
||||||
async with websockets.connect(uri) as websocket:
|
async with websockets.connect(uri) as websocket:
|
||||||
|
await websocket.send(json.dumps({"op": "subscribe", "args": ["trade"]})) # надеюсь жо этого не дойдет,
|
||||||
|
# но в идеале это не должно понадобиться так как у Дмитрия Андреевича только GET запрос (это POST)
|
||||||
while True:
|
while True:
|
||||||
message = await websocket.recv()
|
resp = await websocket.recv()
|
||||||
encrypted_messages = json.loads(message)
|
print("Получено в зашифрованном виде:", resp)
|
||||||
for encrypted_message in encrypted_messages:
|
|
||||||
decrypted_message = await decrypt_message(encrypted_message)
|
|
||||||
print(decrypted_message)
|
|
||||||
|
|
||||||
asyncio.get_event_loop().run_until_complete(listen())
|
asyncio.run(test_client())
|
||||||
|
#
|
||||||
|
# async def decrypt_message(encrypted_message):
|
||||||
|
# # Декодируем base64
|
||||||
|
# encrypted_data = base64.b64decode(encrypted_message)
|
||||||
|
#
|
||||||
|
# # Извлекаем IV и зашифрованный текст
|
||||||
|
# iv = encrypted_data[:IV_LENGTH]
|
||||||
|
# cipher_text = encrypted_data[IV_LENGTH:]
|
||||||
|
#
|
||||||
|
# # Создаем объект Cipher для расшифровки
|
||||||
|
# cipher = Cipher(algorithms.AES(KEY), modes.CBC(iv), backend=default_backend())
|
||||||
|
# decryptor = cipher.decryptor()
|
||||||
|
#
|
||||||
|
# # Расшифровываем данные
|
||||||
|
# decrypted_data = decryptor.update(cipher_text) + decryptor.finalize()
|
||||||
|
#
|
||||||
|
# # Удаляем PKCS5Padding
|
||||||
|
# padding_length = decrypted_data[-1]
|
||||||
|
# decrypted_data = decrypted_data[:-padding_length]
|
||||||
|
#
|
||||||
|
# return decrypted_data.decode('utf-8')
|
||||||
|
# async def listen():
|
||||||
|
# uri = "ws://45.67.56.214:8088/users"
|
||||||
|
# async with websockets.connect(uri) as websocket:
|
||||||
|
# while True:
|
||||||
|
# message = await websocket.recv()
|
||||||
|
# encrypted_messages = json.loads(message)
|
||||||
|
# for encrypted_message in encrypted_messages:
|
||||||
|
# decrypted_message = await decrypt_message(encrypted_message)
|
||||||
|
# print(decrypted_message)
|
||||||
|
#
|
||||||
|
# asyncio.get_event_loop().run_until_complete(listen())
|
Loading…
Reference in New Issue
Block a user