def split_parts_list(n, k, prime, img, path_pic): h, w, rgb = img.shape # height, image width name, ext = path.splitext(path_pic) # split to image path and extension np_lists = np.zeros(shape=(n, h, w, 3)) # np_lists = [[] for i in range(n)] # blank list, for shares of picture shrs = [[[[] for j in range(w)] for i in range(h)], [[[] for j in range(w)] for i in range(h)], [[[] for j in range(w)] for i in range(h)] ] # share values for each pixel RGB : shrs[0] is red ... # the image is a matrix = a series of rows of pixels row_count = 0 for row in img: # for each row in img new_rows = np.zeros(shape=(n, w, 3)) # new_rows = [[] for j in range(n)] # we make new rows, ie as many rows as we have division = n pix_count = 0 for pix in row: if len(pix) == 3: r, g, b = pix[0], pix[1], pix[ 2] # check that the pixel is plain => three values => RGB else: # or has 4 values, where the alpha indicator is the first value r, g, b = pix[1], pix[2], pix[3] p1, p2, p3 = Scheme(r, n, k, prime), Scheme( g, n, k, prime ), Scheme( b, n, k, prime ) # each color value in a pixel is divided by SSSA into n values sh1, sh2, sh3 = p1.construct_shares_image( ), p2.construct_shares_image(), p3.construct_shares_image() for i in range(n): new_rows[i][pix_count] = [ sh1[i + 1], sh2[i + 1], sh3[i + 1] ] # we add newly created pixels to existing strings of new images shrs[0][row_count][pix_count] = sh1 shrs[1][row_count][pix_count] = sh2 shrs[2][row_count][pix_count] = sh3 pix_count += 1 row_count += 1 v = 0 for el in range(n): np_lists[el][row_count - 1] = new_rows[ el] #adding the entire row to the shares matrix - image v += 1 i = 0 for image in np_lists: new_img = Image.fromarray(image.astype( 'uint8')) #creating shares - images from newly created matrices cuvanje = name + "_share" + str(i) cuvanje += ".png" new_img.save(cuvanje) i += 1 return shrs
def split_parts_list(n, k, prime, img, path_pic): h, w, rgb = img.shape # visina, sirina slike name, ext = path.splitext(path_pic) # putanja slike, odvajanje ekstenzije np_lists = np.zeros(shape=(n, h, w, 3)) # np_lists = [[] for i in range(n)] # prazne liste, za shares - slike shrs = [[[[] for j in range(w)] for i in range(h)], [[[] for j in range(w)] for i in range(h)], [[[] for j in range(w)] for i in range(h)] ] # shares vrijednosti za svaki piksel RGB : shrs[0] je crvena ... # slika je matrica = niz nizova(redova) piksela row_count = 0 for row in img: # za svaki red u nizu redova new_rows = np.zeros(shape=(n, w, 3)) # new_rows = [[] for j in range(n)] # pravimo nove redove tj onoliko redova koliko imamo podjela = n pix_count = 0 for pix in row: if len(pix) == 3: r, g, b = pix[0], pix[1], pix[ 2] # provjera da li je piksel obicni => tri vrijednosti => RGB else: # ili ima 4 vrijednosti, gdje je indikator alfa prva vrijednost r, g, b = pix[1], pix[2], pix[3] p1, p2, p3 = Scheme(r, n, k, prime), Scheme( g, n, k, prime ), Scheme( b, n, k, prime ) # svaku vrijednost boja u pikselu dijelimo SSSA-om na n vrijednosti sh1, sh2, sh3 = p1.construct_shares_image( ), p2.construct_shares_image(), p3.construct_shares_image() for i in range(n): new_rows[i][pix_count] = [ sh1[i + 1], sh2[i + 1], sh3[i + 1] ] # u postojece nizove novih slika dodajemo novonastale piksele shrs[0][row_count][pix_count] = sh1 shrs[1][row_count][pix_count] = sh2 shrs[2][row_count][pix_count] = sh3 pix_count += 1 row_count += 1 v = 0 for el in range(n): np_lists[el][row_count - 1] = new_rows[ el] # dodavanje citavog reda u matrice shares - slika v += 1 i = 0 for image in np_lists: new_img = Image.fromarray(image.astype( 'uint8')) # kreiranje shares - slika od novonastalih matrica cuvanje = name + "_share" + str(i) cuvanje += ".png" new_img.save(cuvanje) i += 1 return shrs
def main(): gb = import_gb("cut", 2) param = get_param() scheme = Scheme(gb) scheme.set_data(param) # exporter save = pp.Exporter(gb, "case5", folder_name="solution") vars_to_save = scheme.vars_to_save() # post process scheme.extract() save.write_vtk(vars_to_save, time_step=0) for i in np.arange(param["time"]["num_steps"]): print("processing", i, "step at time", i * param["time"]["step"]) # do one step of the splitting scheme scheme.one_step_splitting_scheme() # post process time = param["time"]["step"] * (i + 1) save.write_vtk(vars_to_save, time_step=time) time = np.arange(param["time"]["num_steps"] + 1) * param["time"]["step"] save.write_pvd(time)
def main(): mesh_size = np.power(2., -7) gb = create_gb(mesh_size) param = get_param() scheme = Scheme(gb) scheme.set_data(param) # exporter folder = "./case2/" save = pp.Exporter(gb, "case2", folder_name=folder+"solution_ml") vars_to_save = scheme.vars_to_save() # post process save.write_vtk(vars_to_save, time_step=0) for i in np.arange(param["time"]["num_steps"]): time = (i+1)*param["time"]["step"] print("processing", i, "step at time", time) # do one step of the splitting scheme scheme.one_step_splitting_scheme(time) # post process save.write_vtk(vars_to_save, time_step=time) time = np.arange(param["time"]["num_steps"]+1)*param["time"]["step"] save.write_pvd(time)
def encrypt_text(self): self.listWidget_4.clear() if self.textEdit.toPlainText() is None or self.textEdit.toPlainText( ) == "": self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Грешка", "Молим унесите текст за енкрипцију") self.error_message.exec_() elif self.spinBox_4.value() == 0 or self.spinBox_4.value( ) < self.spinBox_3.value() or self.spinBox_3.value( ) == 0 or self.spinBox_3.value() < 2 or self.spinBox_4.value() < 2: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Грешка", "Неки од броја подјела није добар") self.error_message.exec_() else: self.secret_text = self.textEdit.toPlainText() text = [ord(c) for c in self.secret_text] self.glavna_lista = [[] for i in range(len(self.secret_text))] shares, lista = [], [] for el in text: s = Scheme(el, self.spinBox_4.value(), self.spinBox_3.value(), 127) shares = s.construct_shares() lista.append(shares) print(lista) self.text_shares = lista words_list = [''] * self.spinBox_4.value() for dic in lista: dict_variable = {} counter = 0 for (key, value) in dic.items(): if value < 32: dict_variable[key] = spec_chars[value] words_list[counter] += dict_variable[key] else: dict_variable[key] = chr(value) words_list[counter] += dict_variable[key] counter += 1 print(dict_variable) print(words_list) for word in words_list: self.listWidget_4.addItem(word)
def encrypt_text(self): self.listWidget_4.clear() if self.textEdit.toPlainText() is None or self.textEdit.toPlainText( ) == "": self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Error", "Please enter text for encryption") self.error_message.exec_() elif self.spinBox_4.value() == 0 or self.spinBox_4.value( ) < self.spinBox_3.value() or self.spinBox_3.value( ) == 0 or self.spinBox_3.value() < 2 or self.spinBox_4.value() < 2: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Error", "Some of the number of divisions is not good") self.error_message.exec_() else: self.secret_text = self.textEdit.toPlainText() text = [ord(c) for c in self.secret_text] self.glavna_lista = [[] for i in range(len(self.secret_text))] shares, lista = [], [] for el in text: s = Scheme(el, self.spinBox_4.value(), self.spinBox_3.value(), 127) shares = s.construct_shares() lista.append(shares) print(lista) self.text_shares = lista words_list = [''] * self.spinBox_4.value() for dic in lista: dict_variable = {} counter = 0 for (key, value) in dic.items(): if value < 32: dict_variable[key] = spec_chars[value] words_list[counter] += dict_variable[key] else: dict_variable[key] = chr(value) words_list[counter] += dict_variable[key] counter += 1 print(dict_variable) print(words_list) for word in words_list: self.listWidget_4.addItem(word)
def OnClick(self, event): """ Event bind to 'Generate' button """ # Validation valid = self.validation() if valid == True: pass else: return None pyplot.close("all") filter_ = Filter(self.fp, self.fs, self.gpass, self.gstop, ftype=self.ftype, btype=self.btype) filter_.step_response() filter_.phase_response() filter_.poles_zeros() filter_.freq_response() if self.ftype == "ellip": pass else: ladder = LCladder(self.R1, self.R2, self.fp, self.fs, self.gpass, self.gstop, ftype=self.ftype, btype=self.btype) if filter_.btype == "lowpass": if self.R1 == self.R2: lc_ladder_elements = ladder.load_matched() else: lc_ladder_elements = ladder.load_not_matched() scheme = Scheme(self.R1, self.R2, filter_.ord) scheme.design(lc_ladder_elements) frame = wx.Frame(None, size=(scheme.img_size[0], 250)) panel = SchemePanel(frame) frame.Show() pyplot.show()
def create_scheme(inputs, func): """Create a quantization scheme. The first argument is a list of inputs to the second argument, which is a function the defines the algorithm. The numbers of arguments should match. The function will be set with attributes for later optimizations. This API returns an object that has two methods: `quantize` and `downsize`. Parameters ---------- inputs : Tensor or list of Tensor A list of placeholders that are inputs to the algorithm. It can be a single tensor func : callable A function that defines the algorithm Returns ------- Scheme See Also -------- scheme.Scheme.downsize, scheme.Scheme.quantize Examples -------- .. code-block:: python A = hcl.placeholder((10,)) def algo(A): return hcl.compute(A.shape, lambda x: A[x]+1, "B") s = hcl.create_scheme(A, algo) s.downsize(algo.B, hcl.Int(8)) """ if not isinstance(inputs, list): inputs = [inputs] func(*inputs) for op in Schedule.stage_ops: func.__setattr__(op.name, op) return Scheme(inputs, func)
def encrypt_number(self): self.listWidget_6.clear() if self.spinBox_5.value() == 0: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Грешка", "Молим унесите број за енкрипцију") self.error_message.exec_() elif self.spinBox_12.value() == 0 or self.spinBox_12.value( ) < self.spinBox_11.value() or self.spinBox_11.value( ) == 0 or self.spinBox_12.value() < 2 or self.spinBox_11.value() < 2: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Грешка", "Неки од броја подјела није добар") self.error_message.exec_() else: secret = self.spinBox_5.value() self.secret_number = Scheme(secret, self.spinBox_12.value(), self.spinBox_11.value(), 5000003863) # 5000003863 2147483869 self.shares_number = self.secret_number.construct_shares() for sh in self.shares_number: self.listWidget_6.addItem(str(self.shares_number[sh])) self.inputs = []
def encrypt_number(self): self.listWidget_6.clear() if self.spinBox_5.value() == 0: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Error", "Please enter the encryption number") self.error_message.exec_() elif self.spinBox_12.value() == 0 or self.spinBox_12.value( ) < self.spinBox_11.value() or self.spinBox_11.value( ) == 0 or self.spinBox_12.value() < 2 or self.spinBox_11.value() < 2: self.error_message = QtWidgets.QMessageBox( QtWidgets.QMessageBox.Critical, "Error", "Some of the number of divisions is not good") self.error_message.exec_() else: secret = self.spinBox_5.value() self.secret_number = Scheme(secret, self.spinBox_12.value(), self.spinBox_11.value(), 5000003863) # 5000003863 2147483869 self.shares_number = self.secret_number.construct_shares() for sh in self.shares_number: self.listWidget_6.addItem(str(self.shares_number[sh])) self.inputs = []
from scheme import Scheme start = Scheme().start end = Scheme().end class Node: def __init__(self, x, y): self.position = x, y self.costs = self.calc_costs() def calc_costs(self): # g(n) cost = from staring node cost g = self.calc_distance(*self.position, *start) # h(n) cost = heuristics estimated cost h = self.calc_distance(*self.position, *end) # f(n) cost = g(n) + h(n) f = g + h return (f, h, g) def calc_distance(self, x, y, x2, y2): # calculate estimated distance between two points return abs((x2 - x) + (y2 - y))
import json from scheme import Scheme filename = "/Users/mattlavis/sites and projects/1. Online Tariff/ott prototype/app/data/roo/uk/roo_schemes_uk.json" f = open(filename) data = json.load(f) schemes = data["schemes"] for scheme in schemes: s = Scheme(scheme) ret = s.validate() if ret is not None: print(ret)