Exemplo n.º 1
0
def oracle(ciphertext):
    ciphertext = base64.b64encode(ciphertext)
    sock = mysocket.mysocket(host, port)
    sock.sendline(ciphertext)
    recv = sock.recvline().lower()
    print ciphertext, recv
    return "correct" in recv and not "incorrect" in recv
Exemplo n.º 2
0
Arquivo: server.py Projeto: niuwa/byte
def main():
  ss = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  ss.bind(('localhost', 8080))
  ss.listen(5)
  while 1:
    (cs, address) = ss.accept()
    s = mysocket.mysocket(cs)
    print s.receive(5)
    s.send('world')
    s.close()

if __name__ == "__main__":
    if len(sys.argv) is not 3:
        print "Usage:"
        print "python %s <host> <port>" % (sys.argv[0])
        sys.exit(0)

    host = sys.argv[1]

    try:
        port = int(sys.argv[2])
    except:
        print "port must be an int"
        sys.exit(0)

    sock = mysocket.mysocket(host, port)

    line = ""
    while "enter" not in sock.recvline().lower():
        pass
    sock.sendline("")
    while True:
        line = sock.recvline()
        try:
            num = int(line)
        except:
            print line
            break
        sock.sendline(sol(num))
Exemplo n.º 4
0
####################################################
#
# INIZIO PROGRAMMA
#
####################################################

# Preparativi
# PARTE DI CONNESSIONE VERSO BOB
filename = 'decrypted.jpg'
BOB = "localhost"  # INDIRIZZO DI BOB
PORT = 55711
CHUNK_DIM = 14

t1 = time.time()
# Bob sta aspettando mi connetta a lui
sock = mysocket.mysocket()
print("Inizio la connessione:")
sock.connect(BOB, PORT)
print("Connesso a %s:%d" % (BOB, PORT))

# Attendo N ed E
print("Attendo N, E, num_chunk")
N = mpz((sock.receive(8)))  # ricevo N
print("Ho ricevuto N %d" % N)
E = mpz((sock.receive(8)))  # ricevo E
print("Ho ricevuto E %d" % E)

# ack 1 per bob
ack_for_bob()

print("Attendo chunk_num")
Exemplo n.º 5
0
#	Main
#
#################################################

import mysocket
import socket
import threading 
import os.path
from serverThread import *

#inizializzo un database (creo tre tabelle) se non esiste gia'
if not(os.path.isfile('database')):
    initializeDB('database')

#crea una socket INET di tipo STREAM
serversocket = mysocket.mysocket()

#si associa il socket ad un host pubblico ed alla porta 3000
##serversocket.bind("fd00:0000:0000:0000:e6ce:8fff:fe0a:5e0e", 3007)
serversocket.bind("0000:0000:0000:0000:0000:0000:0000:0001" , 3013)
#serversocket.bind("fd00:0000:0000:0000:9afe:94ff:fe3f:b0f2", 3000)

#metto la socket in ascolto
serversocket.listen(100)

print "Directory listening..."

while True:
	print "Waiting for connection..."
	#accetta le connessioni dall'esternoi
	socketclient, address = serversocket.accept()
Exemplo n.º 6
0
    #SPLI print("In attesa di Bob")
    ack = mpz((new_sock.receive(8)))


def ack_for_bob():
    #SPLI print("Ack inviato a Bob")
    new_sock.send(myzfill(N, 8))


#####################################################################

#INIZIA NOSTRO PROGRAMMA

#####################################################################

sock = mysocket.mysocket()
sock.bind("localhost", PORT)
sock.listen(5)
print("Server on.")
print("Waiting for connection...")
new_sock, address = sock.accept()
print("Connessione stabilita con: ", address)
new_sock = mysocket.mysocket(new_sock)

#####################################################################
#####################################################################
P = generateLargePrime(8)  #P ha 8 cifre
Q = generateLargePrime(8)  #Q ha 8 cifre
print("Questo e' P: %d " % P)
print("Questo e' Q: %d " % Q)
N = mpz(P * Q)  # N di alice
Exemplo n.º 7
0
#FACCIO UN PADDING
resto = image_len % CHUNK_DIM  # verifico che il numero di bits dell'immagine sia multiplo esatto di CHUNK_DIM=16
if (resto != 0):
    for i in range(CHUNK_DIM - resto):
        image.append('0b0')
    image_len = image.length
    print('L\'immagine e\' stata modificata.')
    print("Immagine : %d Bits" % image_len)

#controllo di quanti chunk e' formata l'immagine
num_chunk = image_len / CHUNK_DIM
print('La nostra immagine e\' composta da: %d chunk, ciascuno di 6 bits' %
      num_chunk)

#Aspetto Oracle
sockoracle = mysocket.mysocket()
#SPLI sockoracle.bind("0.0.0.0", PORT)
sockoracle.bind("localhost", PORT1)
sockoracle.listen(5)
print("Server on.")
print("Waiting for connection...")
new_sockoracle, address2 = sockoracle.accept()
print("Connessione stabilita con: ", address2)
new_sockoracle = mysocket.mysocket(new_sockoracle)

#Mi collego ad Alice
sock = mysocket.mysocket()
print("Inizio la connessione:")
#SPLI sock.connect(ALICE, PORT)
sock.connect("localhost", PORT)
print("Connesso ad Alice, PORT %d" % PORT)
Exemplo n.º 8
0
longi = -76.8270829 #deg
reflla = np.array([[lat],[longi],[0.0]])
refpos_ecef = lla2ecef(reflla)
#lat = location.latitude #deg
#longi = location.longitude # deg 

sample = 0
f2hex = np.vectorize(float_to_hex,otypes=[object])
d2hex = np.vectorize(double_to_hex,otypes=[object])
i2hex = np.vectorize(hex,otypes=[object])
#bytetable = np.empty([54,len(t)],dtype=object)

startpacket = '7E7E7E'.decode('hex')
endpacket = '7F7F7F'.decode('hex')

socket = mysocket.mysocket()
socket.connect(socket.gethostname(),10007)

for i in range(len(t)):
    bytepackets = bytearray()
    bytepackets.extend(startpacket)
    tlocal = Time.localtime()
    date[0][i] = tlocal.tm_year*10000 + tlocal.tm_mon*100+tlocal.tm_mday
    time[0][i] = tlocal.tm_hour*10000 + tlocal.tm_min*100 + tlocal.tm_sec
    year[0][i] = tlocal.tm_year-2000
    month[0][i] = tlocal.tm_mon
    day[0][i] = tlocal.tm_mday
    hour[0][i] = tlocal.tm_hour
    minute[0][i] = tlocal.tm_min
    second[0][i] = tlocal.tm_sec
    
Exemplo n.º 9
0
import mysocket, time

serverSocket = mysocket.mysocket()
serverPort = 12000
serverSocket.bind(('',serverPort))
serverSocket.listen(1)
print 'The server is ready to receive'
# while 1:
connectionSocket, addr = serverSocket.accept()
count = 0
while 1:
	sentence = connectionSocket.recv(1024)
	if len(sentence) == 0:
		break;
	print sentence
	count += 1
connectionSocket.close()
print count
Exemplo n.º 10
0
sys.path.append('/home/pi/picopter/Adafruit/Adafruit_PWM_Servo_Driver/')
from Adafruit_PWM_Servo_Driver import PWM
import RPi.GPIO as GPIO
import pygame
import mysocket

#initialise classes
pwm = PWM(0x40)
pwm.setPWMFreq(50)

GPIO.setmode(GPIO.BCM)  #use GPIO numering
GPIO.setup(20, GPIO.OUT, initial=GPIO.LOW)  #set both motor channels to LOW
GPIO.setup(21, GPIO.OUT, initial=GPIO.LOW)

#connect socket
comsocket = mysocket.mysocket()
comsocket.myhost('192.168.137.137', 10000)

BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
pygame.init()
size = [400, 200]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Pimobile remote window")

# Used to manage how fast the screen updates
clock = pygame.time.Clock()


#define functions
def setspeed(spdemand):
Exemplo n.º 11
0
import mysocket, time


sock = mysocket.mysocket()

sock.connect(['192.241.166.195', 12000])

count = 0

with open("aladdin.txt") as file:
    for line in file:
    	sock.send(line)
    	count += 1
print "file closed"
sock.close()
print count