コード例 #1
0
ファイル: LT_encode.py プロジェクト: MoellJ/LTCodes
def main():
    root = tk.Tk()
    root.withdraw()

    input_file_path = filedialog.askopenfilename()
    print(input_file_path)
    output_folder_path = filedialog.askdirectory()

    input_file_size = os.path.getsize(input_file_path)
    print(f'File Size: {input_file_size} Bytes')
    #Ask for chunk size
    chunk_size = inputNumber(
        "How big should one drop be (in Kilobytes) ") * 1024
    chunk_amount = math.ceil(input_file_size / chunk_size)
    print(f'Will split into {chunk_amount} chunks')
    input_file_bytes = get_bytes_from_file(input_file_path)
    input_file_chunks = []
    for i in range(0, len(input_file_bytes), chunk_size):
        input_file_chunks.append(input_file_bytes[i:i + chunk_size])
    #Fill up last chunk:
    input_file_chunks[-1] = input_file_chunks[-1] + b'\0' * (
        chunk_size - len(input_file_chunks[-1]))
    #Ask for amount of drops
    amount_of_drops = inputNumber("How many drops should be produced? ")
    for dropNo in range(0, amount_of_drops):
        bitlist = generate_bitvector(chunk_amount)
        #bitlist = [0,0,1,0,1,1,0,1,0]
        dropData = generate_drop_data(input_file_chunks, bitlist)
        bitvector = BitVector(bitlist=bitlist[::-1])
        drop = LTDrop.LTDrop(os.path.basename(input_file_path),
                             input_file_size, chunk_size, chunk_amount,
                             bitvector.intValue(), dropData)
        drop.save(output_folder_path)
コード例 #2
0
ファイル: a51.py プロジェクト: otilrac/airprobe-1
class lsfr:
    def __init__(self, length, taps, middle_bit, name=""):
        """
        length - length of the register in bits
        taps - feedback taps, for clocking the shift register.
               These correspond to the primitive polynomial
               Example polynomials from A5/1:
               x**19 + x**5 + x**2 + x + 1, x**22 + x + 1,
               or x**23 + x**15 + x**2 + x + 1
        middle_bit - middle bit of each of the three shift registers, for clock control
        name - name of LSFR - for print()
        """
        self.taps = taps
        self.length = length
        self.name = name
        self.value = BitVector(size=length)
        self.clk_bit_nr = length - middle_bit - 1

    def mix(self, liczba):
        """Read value from LSB to MSB and add each bit to LSFR's feedback"""
        for key_bit in reversed(liczba):
            bit = key_bit
            self.clock(bit)

    def clock(self, bit=False):
        """Clock LSFR. Can add value of bit to feedback."""
        for tap in self.taps:
            bit_nr = self.length - tap - 1
            bit = bit ^ self.value[bit_nr]
        self.value << 1
        self.value[self.length - 1] = bit

    def out(self):
        """Clock LSFR. Can add value of bit to loopback."""
        return self.value[0]

    def clk_bit(self):
        """Return clocking bit."""
        return self.value[self.clk_bit_nr]

    def set_value(self, value):
        """Set internal state of LSFR."""
        self.value = BitVector(size=self.length, intVal=value)

    def __str__(self):
        return "%s:%X" % (self.name, self.value.intValue())
コード例 #3
0
ファイル: a51.py プロジェクト: 0x0d/TWILIGHTVEGETABLE
class lsfr:
    def __init__(self, length, taps, middle_bit, name=""):
        """
        length - length of the register in bits
        taps - feedback taps, for clocking the shift register.
               These correspond to the primitive polynomial
               Example polynomials from A5/1:
               x**19 + x**5 + x**2 + x + 1, x**22 + x + 1,
               or x**23 + x**15 + x**2 + x + 1
        middle_bit - middle bit of each of the three shift registers, for clock control
        name - name of LSFR - for print()
        """
        self.taps = taps
        self.length = length
        self.name = name
        self.value = BitVector(size = length);
        self.clk_bit_nr = length-middle_bit-1

    def mix(self, liczba):
        """Read value from LSB to MSB and add each bit to LSFR's feedback"""
        for key_bit in reversed(liczba):
            bit = key_bit
            self.clock(bit)

    def clock(self, bit=False):
        """Clock LSFR. Can add value of bit to feedback."""
        for tap in self.taps:
            bit_nr = self.length - tap - 1
            bit = bit ^ self.value[bit_nr]
        self.value << 1
        self.value[self.length-1] = bit

    def out(self):
        """Clock LSFR. Can add value of bit to loopback."""
        return self.value[0]

    def clk_bit(self):
        """Return clocking bit."""
        return self.value[self.clk_bit_nr]

    def set_value(self, value):
        """Set internal state of LSFR."""
        self.value = BitVector(size=self.length, intVal=value)

    def __str__(self):
        return "%s:%X" %  (self.name, self.value.intValue())
コード例 #4
0
ファイル: a51.py プロジェクト: otilrac/airprobe-1
 def gen_block(self, size):
     out = BitVector(size=0)
     for i in xrange(0, size):
         self._clock_regs()
         out = out + BitVector(intVal=int(self._out_bit()))
     return out.intValue()
コード例 #5
0
ファイル: a51.py プロジェクト: 0x0d/TWILIGHTVEGETABLE
 def gen_block(self,size):
     out = BitVector(size=0)
     for i in xrange(0, size):
         self._clock_regs()
         out =   out + BitVector(intVal = int(self._out_bit()))
     return out.intValue()