new algo
This commit is contained in:
28
udod.py
28
udod.py
@@ -1,26 +1,30 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import base64
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
def shift(b, s):
|
||||||
|
r = b + s
|
||||||
|
if r >= 256:
|
||||||
|
r -= 256
|
||||||
|
elif r < 0:
|
||||||
|
r += 256
|
||||||
|
return r
|
||||||
|
|
||||||
def shift_seq(seq, byte_shift):
|
def shift_seq(seq, byte_shift):
|
||||||
result = bytearray(seq)
|
result = bytearray(seq)
|
||||||
for i in range(len(seq)):
|
for i in range(min(len(seq),128)):
|
||||||
result[i] = (result[i] + byte_shift) & 0xff
|
result[i] = (result[i] + byte_shift) & 0xff
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def encrypt(data):
|
def encrypt(data):
|
||||||
return shift_seq(data, 15)
|
return shift_seq(data, 15)
|
||||||
|
|
||||||
|
|
||||||
def decrypt(data):
|
def decrypt(data):
|
||||||
return shift_seq(data, -15)
|
return shift_seq(data, -15)
|
||||||
|
|
||||||
|
|
||||||
class Duplex:
|
class Duplex:
|
||||||
def __init__(self, s1, s1_remote, s1_transform,
|
def __init__(self, s1, s1_remote, s1_transform, s2, s2_remote, s2_transform, loop, mtu):
|
||||||
s2, s2_remote, s2_transform,
|
|
||||||
loop, mtu):
|
|
||||||
self.mtu = mtu
|
self.mtu = mtu
|
||||||
self.loop = loop
|
self.loop = loop
|
||||||
|
|
||||||
@@ -31,11 +35,11 @@ class Duplex:
|
|||||||
print("Starting stream", rx.getsockname(), '>>', tx_addr)
|
print("Starting stream", rx.getsockname(), '>>', tx_addr)
|
||||||
while True:
|
while True:
|
||||||
data = await self.loop.sock_recv(rx, self.mtu)
|
data = await self.loop.sock_recv(rx, self.mtu)
|
||||||
# print(rx.getsockname(),'>>', tx_addr, len(data),
|
#print(rx.getsockname(),'>>', tx_addr, len(data), data[:20].hex(), transform(data)[:20].hex())
|
||||||
# data[:20].hex(), transform(data)[:20].hex())
|
|
||||||
await self.loop.sock_sendto(tx, transform(data), tx_addr)
|
await self.loop.sock_sendto(tx, transform(data), tx_addr)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
rx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
rx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
rx.setblocking(False)
|
rx.setblocking(False)
|
||||||
@@ -53,13 +57,11 @@ async def main():
|
|||||||
if addr in connections.keys():
|
if addr in connections.keys():
|
||||||
tx = connections[addr]
|
tx = connections[addr]
|
||||||
else:
|
else:
|
||||||
connections[addr] = socket.socket(
|
connections[addr] = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
socket.AF_INET, socket.SOCK_DGRAM)
|
|
||||||
tx = connections[addr]
|
tx = connections[addr]
|
||||||
tx.setblocking(False)
|
tx.setblocking(False)
|
||||||
tx.bind(tx.getsockname())
|
tx.bind(tx.getsockname())
|
||||||
Duplex(rx, addr, RX_ALGO, connections[addr],
|
Duplex(rx, addr, RX_ALGO, connections[addr], (TX_IP, TX_PORT), TX_ALGO, loop, RX_MTU)
|
||||||
(TX_IP, TX_PORT), TX_ALGO, loop, RX_MTU)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tx.sendto(TX_ALGO(data), (TX_IP, TX_PORT))
|
tx.sendto(TX_ALGO(data), (TX_IP, TX_PORT))
|
||||||
@@ -75,7 +77,7 @@ if __name__ == '__main__':
|
|||||||
RX_ALGO = encrypt
|
RX_ALGO = encrypt
|
||||||
|
|
||||||
TX_IP = "194.135.105.21"
|
TX_IP = "194.135.105.21"
|
||||||
TX_PORT = 5005
|
TX_PORT = 25565
|
||||||
TX_ALGO = decrypt
|
TX_ALGO = decrypt
|
||||||
|
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|||||||
Reference in New Issue
Block a user