def stvori_omotnicu(self, in_dat, privatni_dat, javni_dat, out_dat, aes_key_len): f = open(in_dat) data = f.read() f.close() kl = aes_key_len // 8 #print kl tajni_kljuc = '' for i in range(0, kl): tajni_kljuc = tajni_kljuc + '1' #tajni_kljuc = '1111111111111111' obj = AES.new(tajni_kljuc,AES.MODE_CFB,"This is an IV456") sifrirana = obj.encrypt(data) sifr = base64.b64encode(sifrirana) key, key_len = self.compose_keys(privatni_dat, javni_dat) self.key = key self.tajni_kljuc = tajni_kljuc public_key = key.publickey() sifrirani_tajni = public_key.encrypt(tajni_kljuc, 32) #print sifrirani_tajni sifr_tajni = binascii.hexlify(sifrirani_tajni[0]) #print sifr_tajni f = open(out_dat, 'w') f.write('---BEGIN OS2 CRYPTO DATA---\n') KSI.put_data_s('File name',out_dat,None,f) KSI.put_data_s('Method','AES\n RSA',None,f) KSI.put_data_s('Key length',key_len+'\n '+hex(len(tajni_kljuc)*8),None,f) KSI.put_data('Envelope data', sifr, f) KSI.put_data('Envelope crypt key',sifr_tajni,f) f.write('---END OS2 CRYPTO DATA---\n') f.close() self.poruka = [sifrirana,sifrirani_tajni] print "[AP] omotnica generirana!"
def get_data(self,in_dat_private, in_dat_public): f = open(in_dat_private,'r') data_private = KSI.load(f) f.close() modulus = int(''.join(data_private['Modulus']),16) private_exponent = int(''.join(data_private['Private exponent']),16) #print "modulus:",modulus #print "private:", private_exponent f = open(in_dat_public) data_public = KSI.load(f) f.close() public_exponent = int(''.join(data_public['Public exponent']),16) #print "public", public_exponent return modulus, private_exponent, public_exponent
def get_data(self, in_dat, out_dat, key_data): f = open(key_data,'r') data = KSI.load(f) f.close() #print data key = ''.join(data['Secret key']) self.key = key
def apMass(shear1, shear2, Mw=None, Mm=None, size=2 * tmax + 7, tmax=tmax): if Mw.any(): shear1 *= Mw shear2 *= Mw shear1 = snd.filters.gaussian_filter( shear1, 0) #smooth(shear1,0) #to get rid of the endien problem shear2 = snd.filters.gaussian_filter(shear2, 0) #smooth(shear2,0) shear1 = shear1.astype(float64) shear2 = shear2.astype(float64) Q0, phi = Q_kernel(size) apMmap = KSI.apMass_calc(shear1, shear2, Q0, phi) if Mm.any(): weight = (Mw * Mm).astype(float64) apM_norm = KSI.apMass_norm(weight, Q0) apMmap /= apM_norm apMmap[isnan(apMmap)] = 0 return apMmap
def KS93(shear1, shear2): '''KS-inversion from shear to convergence, using Schneider eq 44. Requires cython code KSI.pyx''' smap = shear1 + shear2 * 1.0j smap = smap smap = smap.astype(complex128) D = D_kernel(31) D = D.astype(complex128) kmap = KSI.KSI_calc(smap, D) return real(kmap)
def generiraj_digitalni_potpis(self, ulaz_dat, privatni_dat, javni_dat, potpis_dat): f = open(ulaz_dat) data = f.read() f.close() m = SHA.new() m.update(data) sazetak = m.hexdigest() #print sazetak key, key_len = self.compose_keys(privatni_dat, javni_dat) potpis = key.sign(sazetak,'') potpis_txt = hex(potpis[0])[2:-1] #print "ja sam potpis", len(potpis_txt) f = open(potpis_dat, 'w') f.write('---BEGIN OS2 CRYPTO DATA---\n') KSI.put_data_s('Description','Signature',None,f) KSI.put_data_s('File name',potpis_dat,None,f) KSI.put_data_s('Method','SHA-1\n RSA',None,f) KSI.put_data_s('Key length','0xa0\n '+key_len,None,f) KSI.put_data('Signature',potpis_txt,f) f.write('---END OS2 CRYPTO DATA---\n') f.close() self.poruka = [data, potpis] self.key = key print "[AP] potpis generiran!"
def generate_key(self, key_dat, key_size): key = '' key_len = key_size // 8 #print key_len for i in range(0, key_len): num = random.randint(0,15) key = key + hex(num)[2:] #print len(key) f = open(key_dat, 'w') f.write('---BEGIN OS2 CRYPTO DATA---\n') KSI.put_data_s('Method','AES',None,f) KSI.put_data_s('Key length',hex(key_size),None,f) KSI.put_data_s('Secret key',key,None,f) f.write('---END OS2 CRYPTO DATA---\n') print "[AP] kljuc generiran!" f.close()
def generate_hash(self, in_dat, out_dat): f = open(in_dat) sadrzaj = f.read() f.close() m = SHA.new() m.update(sadrzaj) sazetak = m.hexdigest() f = open(out_dat, "w") f.write('---BEGIN OS2 CRYPTO DATA---\n') KSI.put_data_s('Description','Hash',None,f) KSI.put_data_s('Method','SHA-1',None,f) KSI.put_data_s('Hash data',sazetak, None, f) f.write('---END OS2 CRYPTO DATA---\n') f.close() print "[AP] sazetak generiran!" return sazetak
def encrypt(self, in_dat_private, in_dat_public, in_dat, out_dat): key = self.compose_keys(in_dat_private, in_dat_public) self.key = key public_key = key.publickey() f = open(in_dat) data = f.read() f.close() enc_data = public_key.encrypt(data, 32) #print "AAAAAAAA", pickle.dumps(enc_data[0]) f = open(out_dat,'w') f.write('---BEGIN OS2 CRYPTO DATA---\n') KSI.put_data_s('Description','Crypted file',None,f) KSI.put_data_s('Method','RSA',None,f) KSI.put_data('Data',base64.b64encode(enc_data[0]),f) self.enc_data = enc_data f.write('---END OS2 CRYPTO DATA---\n') f.close() print "[AP] kriptiranje zavrsilo!"
def encrypt(self, in_dat, out_dat, key_dat): f = open(key_dat, 'r') data = KSI.load(f) f.close() kljuc = data["Secret key"][0] print "[AP] tajni kljuc: ",kljuc obj = AES.new(kljuc, AES.MODE_CFB,"This is an IV456") f = open(in_dat, "r") poruka = f.read() sifrirana = obj.encrypt(poruka) sifr = base64.b64encode(sifrirana) #print sifr f = open(out_dat, 'w') f.write('---BEGIN OS2 CRYPTO DATA---\n') KSI.put_data_s('Description','Crypted file',None,f) KSI.put_data_s('Method','AES',None,f) KSI.put_data('Data',sifr,f) self.enc_data = sifrirana self.kljuc = kljuc f.write('---END OS2 CRYPTO DATA---\n') f.close() print "[AP] podaci kriptirani!"
def generate_random_keys(self, privatni_dat, javni_dat, key_len): random_num = Random.new().read key = RSA.generate(key_len) self.key = key print "[AP] modulus:", key.n f1 = open(privatni_dat,'w') f1.write('---BEGIN OS2 CRYPTO DATA---\n') KSI.put_data_s('Description','Private key',None,f1) KSI.put_data_s('Method','RSA',None,f1) KSI.put_data_s('Key length',hex(key_len),None,f1) KSI.put_data_d('Modulus',key.n,-1,f1) KSI.put_data_d('Private exponent',key.d,-1,f1) f1.write('---END OS2 CRYPTO DATA---\n') f1.close() f1 = open(javni_dat,'w') f1.write('---BEGIN OS2 CRYPTO DATA---\n') KSI.put_data_s('Description','Public key',None,f1) KSI.put_data_s('Method','RSA',None,f1) KSI.put_data_s('Key length',hex(key_len),None,f1) KSI.put_data_d('Modulus',key.n,-1,f1) KSI.put_data_d('Public exponent',key.e,-1,f1) f1.write('---END OS2 CRYPTO DATA---\n') f1.close() return key
def generiraj_digitalni_pecat(self, ulaz_dat, javni_primatelja, tajni_primatelja, tajni_posiljatelja, javni_posiljatelja, omotnica_dat, potpis_dat): f = open(ulaz_dat) data = f.read() f.close() tajni_kljuc = '1111111111111111' obj = AES.new(tajni_kljuc,AES.MODE_CFB,"This is an IV456") sifrirana = obj.encrypt(data) C1 = sifrirana sifr = base64.b64encode(sifrirana) key_primatelj, key_len_primatelj = self.compose_keys(tajni_primatelja, javni_primatelja) #par kljuceva primatelja key_posiljatelj, key_len_posiljatelj = self.compose_keys(tajni_posiljatelja, javni_posiljatelja) #par kljuceva posiljatelja self.key_primatelj = key_primatelj self.key_posiljatelj = key_posiljatelj javni_kljuc_primatelja = key_primatelj.publickey() self.tajni_kljuc = tajni_kljuc sifrirani_tajni = javni_kljuc_primatelja.encrypt(tajni_kljuc, 32) C2 = sifrirani_tajni #print sifrirani_tajni sifr_tajni = binascii.hexlify(sifrirani_tajni[0]) #print sifr_tajni f = open(omotnica_dat, 'w') f.write('---BEGIN OS2 CRYPTO DATA---\n') KSI.put_data_s('File name',omotnica_dat,None,f) KSI.put_data_s('Method','AES\n RSA',None,f) KSI.put_data_s('Key length',key_len_primatelj+'\n '+hex(len(tajni_kljuc)*8),None,f) KSI.put_data('Envelope data', sifr, f) KSI.put_data('Envelope crypt key',sifr_tajni,f) f.write('---END OS2 CRYPTO DATA---\n') f.close() f = open(omotnica_dat) data_omotnica = f.read() f.close() m = SHA.new() m.update(data_omotnica) sazetak = m.hexdigest() #print "JAAAAAA", sazetak kriptirani_sazetak = key_posiljatelj.encrypt(sazetak,32) C3 = kriptirani_sazetak potpis = key_posiljatelj.sign(sazetak, '') potpis_txt = hex(potpis[0])[2:-1] f = open(potpis_dat, 'w') f.write('---BEGIN OS2 CRYPTO DATA---\n') KSI.put_data_s('Description','Signature',None,f) KSI.put_data_s('File name',potpis_dat,None,f) KSI.put_data_s('Method','SHA-1\n RSA',None,f) KSI.put_data_s('Key length','0xa0\n '+key_len_posiljatelj,None,f) KSI.put_data('Signature',potpis_txt,f) f.write('---END OS2 CRYPTO DATA---\n') f.close() self.poruka = [C1, C2, potpis] print "[AP] digitalni pecat generiran!"
F2 = fftshift(fftpack.fft2(img2)) psd2D = np.conj(F1) * F2 #calculate cross correlation psd2D /= bell_2D(size, sigmaG1 * PPA) * bell_2D(size, sigmaG2 * PPA) ell_arr, psd1D = azimuthalAverage(psd2D, center=None, edges=edges, logbins=logbins) ell_arr = edge2center(ell_arr) ell_arr *= 360. / sqrt(sizedeg) # normalized to our current map size norm = ((2 * pi * sqrt(sizedeg) / 360.0)**2) / (size**2)**2 powspec = ell_arr * (ell_arr + 1) / (2 * pi) * norm * psd1D return ell_arr, powspec ########## begin: peak counts ############################ peaks_mat = lambda kmap: KSI.findpeak_mat(kmap.astype(float)) peaks_list = lambda kmap: array(KSI.findpeak_list(kmap.astype(float))) def peaks_mask_hist(kmap, mask, bins, kmin=-0.04, kmax=0.12): '''If kamp has a mask, return only peaks have no mask on them, histogramed to binedges. mask = 1 for good non-mask regions, 0 for mask. ''' kmap_masked = kmap * mask kmap_masked[where( mask == 0 )] = kmax * 10 #give a high value to mask region, so even it's considered a peak, it will fall out of the histogram peaks = peaks_list(kmap_masked) peaks_hist = histogram(peaks, range=(kmin, kmax), bins=bins)[0] return peaks_hist