def write_params(sheet1, params, i): text = params[1] key = params[2] enc_dec = params[3] result = params[4] present_SW = present.Present(key) expected_enc_value = present_SW.encrypt(text) expected_dec_value = present_SW.decrypt(text) print("*************************") print(hex(result)) print(hex(expected_enc_value)) print(hex(expected_dec_value)) print("*************************") error = 0 if (enc_dec): if (expected_dec_value != result): error = 1 else: if (expected_enc_value != result): error = 1 sheet1.write(i, 1, hex(text)) sheet1.write(i, 2, hex(key)) sheet1.write(i, 3, hex(enc_dec)) sheet1.write(i, 4, hex(result)) sheet1.write(i, 5, hex(expected_enc_value)) sheet1.write(i, 6, hex(expected_dec_value)) sheet1.write(i, 7, hex(error)) return i + 1
def run_test(dut, key=0): key = random.randint(0, (2**32) - 1) print(hex(key)) present_SW = present.Present(key) setup_function(dut, key) yield rst_function_test(dut, key) yield generate_round_keys(dut) yield check_round_keys(dut, present_SW)
def timer_callback(self, event): if self.last_recieved_stamp is None: return cmd = Odometry() cmd.header.stamp = self.last_recieved_stamp cmd.header.frame_id = 'map' cmd.child_frame_id = 'odom' cmd.pose.pose = self.last_received_pose self.xtry=cmd.pose.pose.position.x self.ytry=cmd.pose.pose.position.y #print str(str("X ")+str(cmd.pose.pose.position.x)) #print str(str("Y ")+str(cmd.pose.pose.position.y)) #print str(str("Z ")+str(cmd.pose.pose.position.z)) cmd.twist.twist = self.last_received_twist self.pub_odom.publish(cmd) """ xParam=float(str(self.last_received_pose)[17:25]) yParam=str(self.last_received_pose)[33:36] #yParam=self.last_received_pose.pose.position.x #xParam=float(str(self.last_received_pose)[25]) print(str(self.last_received_pose)) #print(str("float")+str(float(str(self.last_received_pose)[17:25]))) #print("{0:.0f}".format(xParam)) """ xParam=cmd.pose.pose.position.x yParam=cmd.pose.pose.position.y lastCoordinateX="{0:.0f}".format(xParam) lastCoordinateY="{0:.0f}".format(yParam) key = '10000000000200000000'.decode('hex') cipher = present.Present(key) plainX=binascii.hexlify(lastCoordinateX).decode('hex') plainY=binascii.hexlify(lastCoordinateY).decode('hex') encryptedX = cipher.encrypt(plainX) encryptedY = cipher.encrypt(plainY) self.encryptedX=encryptedX.encode('hex') self.encryptedY=encryptedY.encode('hex') #print str(str("X : ")+str(encryptedX.encode('hex'))) #print str(str("Y : ")+str(encryptedY.encode('hex'))) #print(str(encrypted.encode('hex'))) #print(self.last_received_twist) tf = TransformStamped( header=Header( frame_id=cmd.header.frame_id, stamp=cmd.header.stamp ), child_frame_id=cmd.child_frame_id, transform=Transform( translation=cmd.pose.pose.position, rotation=cmd.pose.pose.orientation ) ) self.tf_pub.sendTransform(tf)
def test_examples_two(self): "Test the Present object creation from example text" # 1. Loop for all of the examples for example in EXAMPLES: # 2. Create Present object from text myobj = present.Present(text=example['text']) # 3. Check the methods self.assertEqual(myobj.wrap(), example['wrap']) self.assertEqual(myobj.bow(), example['bow']) self.assertEqual(myobj.ribbon(), example['ribbon'])
def test_examples(self): "Test the Present object creation from example text" # 1. Loop for all of the examples for example in EXAMPLES: # 2. Create Present object from text myobj = present.Present(text=example['text']) # 3. Check the methods self.assertEqual(myobj.area(), example['area']) self.assertEqual(myobj.slack(), example['slack']) self.assertEqual(myobj.paper(), example['paper'])
def __init__(self, text=None, part2=False): # 1. Set the initial values self.part2 = part2 self.text = text self.presents = [] # 2. Process text (if any) if text is not None and len(text) > 0: for line in text: line = line.strip() if not line or len(line) == 0: continue self.presents.append(present.Present(text=line))
def run_test(dut, key=0): key = random.randint(0, (2**32) - 1) text = random.randint(0, (2**32) - 1) print(hex(key)) print(hex(text)) present_SW = present.Present(key) expected_enc_value = present_SW.encrypt(text) expected_dec_value = present_SW.decrypt(text) setup_function(dut, key, text) yield rst_function_test(dut) yield generate_round_keys(dut) yield enc_dec_test(dut, expected_enc_value, expected_dec_value)
def test_empty_init(self): "Test the default Present creation" # 1. Create default Present object myobj = present.Present() # 2. Make sure it has the default values self.assertEqual(myobj.length, 0) self.assertEqual(myobj.width, 0) self.assertEqual(myobj.height, 0) self.assertEqual(myobj.text, None) # 3. Test methods self.assertEqual(myobj.area(), 0) self.assertEqual(myobj.slack(), 0) self.assertEqual(myobj.paper(), 0)
def __init__(self,c,len_value): self.c = c self.len_value = len_value self.present_right = present.Present(0x00000000000000000000) self.present_left = present.Present(0x00000000000000000000)
def create_microsd_vectors(micro_sd,storage_file,VIOstorage_file,N,e): storage_file.seek(0) #storage_file.write(int(N).to_bytes(4,byteorder='big')) zero = 0 counter_errors = 0 j=0 for i in range(0,N): key = np.random.randint(0,2**63-1,1,dtype=np.int64) text = np.random.randint(0,2**63-1,1,dtype=np.int64) present_SW = present.Present(int(key[0])) expected_enc_value = present_SW.encrypt(int(text[0])) expected_dec_value = present_SW.decrypt(int(text[0])) percent = random.randint(1,100) if(percent < e): expected_enc_value = expected_enc_value + 1 expected_dec_value = expected_dec_value + 1 counter_errors = counter_errors + 1 storage_file.write(int(key[0]).to_bytes(10, byteorder='little')) storage_file.write(int(text[0]).to_bytes(8, byteorder='little')) storage_file.write(int(0).to_bytes(1, byteorder='little')) storage_file.write(expected_enc_value.to_bytes(8, byteorder='little')) storage_file.write(int(key[0]).to_bytes(10, byteorder='little')) storage_file.write(int(text[0]).to_bytes(8, byteorder='little')) storage_file.write(int(1).to_bytes(1, byteorder='little')) storage_file.write(expected_dec_value.to_bytes(8, byteorder='little')) key_string = '{:020x}'.format(int(key[0])) text_string = '{:016x}'.format(int(text[0])) expected_enc_value_string = '{:016x}'.format(expected_enc_value) expected_dec_value_string = '{:016x}'.format(expected_dec_value) VIOstorage_file.write("""{0} {1} 0 {2}\n""".format(key_string,text_string,expected_enc_value_string)) VIOstorage_file.write("""{0} {1} 1 {2}\n""".format(key_string,text_string,expected_dec_value_string)) #clear block micro_sd.seek(BLOCK_SIZE*(NUM_BLOCK_TEST+j)) micro_sd.write(zero.to_bytes(512, byteorder='big')) micro_sd.seek(BLOCK_SIZE*(NUM_BLOCK_TEST+j)) j=j+1 micro_sd.write(SIGNATURE.to_bytes(4, byteorder='big')) micro_sd.write(int(text[0]).to_bytes(8, byteorder='little')) micro_sd.write(int(key[0]).to_bytes(10, byteorder='little')) micro_sd.write(int(0).to_bytes(1, byteorder='little'))#enc micro_sd.write(int(expected_enc_value).to_bytes(8,byteorder='little')) #clear block micro_sd.seek(BLOCK_SIZE*(NUM_BLOCK_TEST+j)) micro_sd.write(zero.to_bytes(512, byteorder='big')) micro_sd.seek(BLOCK_SIZE*(NUM_BLOCK_TEST+j)) j = j+1 micro_sd.write(SIGNATURE.to_bytes(4, byteorder='big')) micro_sd.write(int(text[0]).to_bytes(8, byteorder='little')) micro_sd.write(int(key[0]).to_bytes(10, byteorder='little')) micro_sd.write(int(1).to_bytes(1, byteorder='little'))#enc micro_sd.write(int(expected_dec_value).to_bytes(8,byteorder='little')) #clear block micro_sd.seek(BLOCK_SIZE*(NUM_BLOCK_TEST+j)) micro_sd.write(zero.to_bytes(512, byteorder='big')) return counter_errors
import sys, present file_path = sys.argv[1] total_square_feets, ribon_length = 0, 0 with open(file_path, 'r') as presents: for present_params in presents: length, width, height = map(int, present_params.split('x')) p = present.Present(length, width, height) total_square_feets += p.get_square() ribon_length += p.get_ribon_lenght() print('Total square feets: {}\nRibon length: {}'.format( total_square_feets, ribon_length))