#!/usr/bin/python
# coding-utf-8
#   import the library needed 
import socket
from sys import stdout
from time import time
from binascii import unhexlify

#   some Constants
DEBUG =False 
ZERO= 0.100
ONE =0.175


#   specify the ip and port 
ip = "138.47.102.67"
port = 33333

#   create server, connect, recv first bit data
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip,port))
data = s.recv(4096)

#   intialize the covert binary string
covert_bin=""

#   continue until receive EOF signal
while(data.rstrip("\n") != "EOF"):
    
    #   print it if in DEBUG mode
    
    stdout.write(data)
    stdout.flush()

    #   save the time before receive next message
    t0   = time()

    #   receive 
    data = s.recv(4096)
    
    # t1 = time()
    #   compare the time since receive last message 
    delta = round(time()-t0,3)

    #   print the delay if in DEBUG mode
    if(DEBUG):
        stdout.write(" {}\n".format(delta))
        stdout.flush()

    #   adding 1's and 0's to the covert binary based on the delay 
    if(delta >= ONE):
        covert_bin += "1"
    else:
        covert_bin +="0"

covert = ""
i = 0 




#   go over everything in covert_bin
while(i < len(covert_bin)):
    b = covert_bin[i:i+8]

    n = int("0b{}".format(b),2)

    #   try decode, if failed, add "?"
    try:
        covert += unhexlify("{0:x}".format(n))
    except TypeError:
        covert += "?"
    i += 8


    
result = "Covert message:" + covert
print (result)
s.close()

da9049869acd7b332fb8f51eb1b8da7521f356fc
<mask token>

<mask token>
s.connect((ip, port))
<mask token>
while data.rstrip('\n') != 'EOF':
    stdout.write(data)
    stdout.flush()
    t0 = time()
    data = s.recv(4096)
    delta = round(time() - t0, 3)
    if DEBUG:
        stdout.write(' {}\n'.format(delta))
        stdout.flush()
    if delta >= ONE:
        covert_bin += '1'
    else:
        covert_bin += '0'
<mask token>
while i < len(covert_bin):
    b = covert_bin[i:i + 8]
    n = int('0b{}'.format(b), 2)
    try:
        covert += unhexlify('{0:x}'.format(n))
    except TypeError:
        covert += '?'
    i += 8
<mask token>
print(result)
s.close()

<mask token>
DEBUG = False
ZERO = 0.1
ONE = 0.175
ip = '138.47.102.67'
port = 33333
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, port))
data = s.recv(4096)
covert_bin = ''
while data.rstrip('\n') != 'EOF':
    stdout.write(data)
    stdout.flush()
    t0 = time()
    data = s.recv(4096)
    delta = round(time() - t0, 3)
    if DEBUG:
        stdout.write(' {}\n'.format(delta))
        stdout.flush()
    if delta >= ONE:
        covert_bin += '1'
    else:
        covert_bin += '0'
covert = ''
i = 0
while i < len(covert_bin):
    b = covert_bin[i:i + 8]
    n = int('0b{}'.format(b), 2)
    try:
        covert += unhexlify('{0:x}'.format(n))
    except TypeError:
        covert += '?'
    i += 8
result = 'Covert message:' + covert
print(result)
s.close()

import socket
from sys import stdout
from time import time
from binascii import unhexlify
DEBUG = False
ZERO = 0.1
ONE = 0.175
ip = '138.47.102.67'
port = 33333
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, port))
data = s.recv(4096)
covert_bin = ''
while data.rstrip('\n') != 'EOF':
    stdout.write(data)
    stdout.flush()
    t0 = time()
    data = s.recv(4096)
    delta = round(time() - t0, 3)
    if DEBUG:
        stdout.write(' {}\n'.format(delta))
        stdout.flush()
    if delta >= ONE:
        covert_bin += '1'
    else:
        covert_bin += '0'
covert = ''
i = 0
while i < len(covert_bin):
    b = covert_bin[i:i + 8]
    n = int('0b{}'.format(b), 2)
    try:
        covert += unhexlify('{0:x}'.format(n))
    except TypeError:
        covert += '?'
    i += 8
result = 'Covert message:' + covert
print(result)
s.close()

#!/usr/bin/python
# coding-utf-8
#   import the library needed 
import socket
from sys import stdout
from time import time
from binascii import unhexlify

#   some Constants
DEBUG =False 
ZERO= 0.100
ONE =0.175


#   specify the ip and port 
ip = "138.47.102.67"
port = 33333

#   create server, connect, recv first bit data
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip,port))
data = s.recv(4096)

#   intialize the covert binary string
covert_bin=""

#   continue until receive EOF signal
while(data.rstrip("\n") != "EOF"):
    
    #   print it if in DEBUG mode
    
    stdout.write(data)
    stdout.flush()

    #   save the time before receive next message
    t0   = time()

    #   receive 
    data = s.recv(4096)
    
    # t1 = time()
    #   compare the time since receive last message 
    delta = round(time()-t0,3)

    #   print the delay if in DEBUG mode
    if(DEBUG):
        stdout.write(" {}\n".format(delta))
        stdout.flush()

    #   adding 1's and 0's to the covert binary based on the delay 
    if(delta >= ONE):
        covert_bin += "1"
    else:
        covert_bin +="0"

covert = ""
i = 0 




#   go over everything in covert_bin
while(i < len(covert_bin)):
    b = covert_bin[i:i+8]

    n = int("0b{}".format(b),2)

    #   try decode, if failed, add "?"
    try:
        covert += unhexlify("{0:x}".format(n))
    except TypeError:
        covert += "?"
    i += 8


    
result = "Covert message:" + covert
print (result)
s.close()
