def test_IdentifyValidCheckSum(self):

        validInput = [' _     _  _  _  _  _  _  _ ',
                      ' _||_||_ |_||_| _||_||_ |_ ',
                      ' _|  | _||_||_||_ |_||_| _|',
                      '                           ']
        testEntry = Entry(validInput)
        self.assertTrue(Checksum.isValid(testEntry))
    def test_IdentifyInvalidCheckSumDueToIllegibility(self):

        validInput = [' _  _     _  _        _  _ ',
                      '|_ |_  _| _|     ||_||_||_ ',
                      '|_||_|  | _|  |  |  | _| _|',
                      '                           ']
        testEntry = Entry(validInput)
        self.assertFalse(Checksum.isValid(testEntry))
示例#3
0
    def BuildResults(inputOCR):
        '''Build final result string to be written out to the output file

           keyword arguments: 
           inputOCR: Instance of Entry Class

           returns string
        '''

        result = inputOCR.ToString()

        if inputOCR.illegible:
            result += ' ILL'
        else:
            if not (Checksum.isValid(inputOCR)):
                result += ' ERR'

        return result
def send_file(connection, client_address):
    checksum = Checksum.generate_digest()

    print("sending file", f"{FILENAME}".encode(), "with filesize", FILESIZE,
          "kb", "to client", client_address)
    print("\n")
    with open(FILENAME, "rb") as f:
        # read the bytes from the file
        bytes_read = f.read(BUFFER_SIZE)

        try:
            # we use sendall to assure transimission in
            # busy networks
            connection.sendall(bytes_read)

        except socket.error:
            print("Error sending file")

        try:
            connection.send(b"checksum=" + str.encode(checksum))

        except socket.error:
            print("Error sending checksum")
#Pass Server ID string from command line argument
SERVER_ID = "1"
if ((len(sys.argv) - 1) >= 1):
    SERVER_ID = sys.argv[1]
#Transfer socket
#Determine correct host IP from adapter
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
IP = s.getsockname()[0]
s.close()
TCP_PORT = 3000
#IP Multicast group with UDP socket port
MULTICAST_GROUP = ("224.0.0.0", 10000)
#Use path of FritzBox NAS space
FILENAME = Path("Y:/Gastbereich/file_to_transmit.txt")
Checksum = Checksum(FILENAME)
Multicast = Multicast(SERVER_ID, IP)
# get the file size
FILESIZE = os.path.getsize(FILENAME)
#Receive buffer size
BUFFER_SIZE = 1024


#Server Thread
class Server(multiprocessing.Process):
    def __init__(self, connection, received_data, client_address):
        super(Server, self).__init__()
        self.connection = connection
        self.received_data = received_data
        self.msg = self.received_data.decode()
        self.client_address = client_address
示例#6
0
from Checksum import Checksum
from DragonCurve import DragonCurveUpTo

#10000001111001111110000
#10000011110010000111110
print(DragonCurveUpTo('10000',20))
print(Checksum(DragonCurveUpTo('10000',20)[:20]))
print()
print(Checksum(DragonCurveUpTo('10011111011011001',272)[:272]))
print(Checksum(DragonCurveUpTo('10011111011011001',35651584)[:35651584]))