Best Python code snippet using hypothesis
rsa.py
Source:rsa.py  
...2728    def load_private_key(self, d, n):29        self.privateKey = (d, n)3031    def set_last_block_length(self, new_value):32        self.last_block_length = new_value3334    def show_info(self, info):35        if self.display_info == False:36            return37        print(info)38        time.sleep(0.1)3940    def crypto(self, block):41        return pow(block, self.publicKey[0], self.publicKey[1])4243    def decrypto(self, block):44        return pow(block, self.privateKey[0], self.privateKey[1])45
...bin.py
Source:bin.py  
1# Author: Sebastian Merz2# Licence: GNU General Public License v3.03# Description: script for converting binary data from a Siglent oscilloscopes and converting it into usable data4# Example:5#   from bin import bin6#   data = bin(<file_path>).convert()7import struct8class bin:9    magnitudes = [10e-24, 10e-21, 10e-18, 10e-15, 10e-12, 10e-9, 10e-6, 10e-3, 1, 10e3, 10e6, 10e9, 10e12, 10e15]10    file = ''11    def __init__(self, file):12        self.file = file13    def data_to_unit(self, data):14        result = []15        for i in range(0, int(len(data) / 16)):16            packet = data[(i+1)*16-16:(i+1)*16]17            result.append(struct.unpack('d', packet[:8])[0] * self.magnitudes[struct.unpack('i', packet[8:12])[0]])18        return result if len(result) > 1 else result[0]19    def data_to_int(self, data):20        result = []21        count = int(len(data) / 4)22        for i in range(0, count):23            packet = data[(i + 1) * 4 - 4:(i + 1) * 4]24            result.append(struct.unpack('i', packet)[0])25        return result if len(result) > 1 else result[0]26    def convert(self):27        f = open(self.file, 'rb+')28        file_data = f.read()29        channel_states = self.data_to_int(file_data[:16])30        channel_volt_division = self.data_to_unit(file_data[16:80])31        channel_offset = self.data_to_unit(file_data[80:144])32        #digital_states = self.data_to_int(file_data[144:212])33        horizontal_list = self.data_to_unit(file_data[212:244])34        wave_length = self.data_to_int(file_data[244:248])35        sample_rate = self.data_to_unit(file_data[248:264])36        #digital_wave_length = self.data_to_int(file_data[264:268])37        #digital_sample_rate = self.data_to_unit(file_data[268:284])38        #reserved = file_data[284:2048] #1764 bits reserved space39        data = file_data[2048:]40        f.close()41        print('channel_states: ', channel_states)42        print('channel_volt_division: ', channel_volt_division)43        print('channel_offset: ', channel_offset)44        #print('digital_states: ', digital_states)45        print('horizontal_list: ', horizontal_list)46        print('wave_length: ', wave_length)47        print('sample_rate: ', sample_rate)48        #print('digital_wave_length: ', digital_wave_length)49        #print('digital_sample_rate: ', digital_sample_rate)50        block_length = (1000000 if len(data) >= 14e6 or wave_length >= 1E6 else wave_length)51        block_number = int(wave_length // block_length)52        last_block_length = wave_length % block_length53        block_number = (block_number + 1 if last_block_length != 0 else block_number)54        result = []55        for block in range(0, block_number):56            if block == (block_number - 1) and last_block_length != 0:57                block_data = range(block_length * block, block_length + last_block_length)58            else:59                block_data = range(block_length * block, block_length * (block + 1))60            output = []61            for i in block_data:62                counter = 063                volt = []64                for channel in range(0, len(channel_states)):65                    if channel_states[channel]:66                        volt_raw = int(data[i + (counter * wave_length)])67                        volt_res = (volt_raw - 128) * channel_volt_division[channel] / 25 - channel_offset[channel]68                        volt.append(float(format(volt_res, '.12f')))69                        counter += 170                if counter > 0:71                    volt.insert(0, float(format(-horizontal_list[0] * 14 / 2 + i * (1 / sample_rate), '.12f')))72                output.append(volt)73            result.append(output)...break_repeating_key.py
Source:break_repeating_key.py  
1from base64 import b64decode2import hamming_distance3from binascii import hexlify4from single_byte_xor import brute_force_split5from repeating_key_xor_encrypt import decrypt6def load_file():7    r = ''8    with open('blocks.txt', 'r') as f:9        for line in f:10            r += line.rstrip('\n')11    return r12def split_hex_string(hex_string):13    return [hex_string[i:i+2] for i in range(0, len(hex_string), 2)]14def make_blocks(hex_array, key_size):15    return [hex_array[i:i+key_size] for i in range(0, len(hex_array), key_size)]16def make_blocks_with_padding(hex_array, key_size, padding_value):17    blocks = make_blocks(hex_array, key_size)18    last_block_index = len(blocks)-119    last_block_length = len(blocks[last_block_index])20    if last_block_length is not key_size:21        for x in range(last_block_length, key_size):22            blocks[last_block_index].append(padding_value)23    return blocks24def block_distance_normalized(block_1, block_2, key_size):25    return hamming_distance.calculate_hex(block_1, block_2) / key_size26def get_key_score(hex_array, key_range_max, return_sorted=False):27    r = dict()28    for x in range(1, KEY_RANGE):29        b = make_blocks(hex_array, x)30        r[x]=block_distance_normalized(b[0], b[1], x)31    if return_sorted:32        return sorted(r.items(), key = lambda p: p[1])33    return r34def transpose(blocks):35    return list(zip(*blocks))36def examine_keys(matrix):37    for v in matrix:38        results = brute_force_split(v)39        results = sorted(results.items(), key = lambda p: p[1])40        for r in results:41            print(r)42        input('Press any key to continue..')43        44KEY_RANGE = 4045s = load_file()46h = hexlify(b64decode(s))47hex_array =  split_hex_string(h)48#print(get_key_score(hex_array, KEY_RANGE, return_sorted=True))49KEY_SIZE = 550PADDING_VALUE = b'ff'51blocks = make_blocks_with_padding(hex_array, KEY_SIZE, PADDING_VALUE)52transposed_matrix = transpose(blocks)53#examine_keys(transposed_matrix)54#KEY: ionio55print(decrypt(s, 'ionio'))56#hamming distance test...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
