def stan(): cl = int(input("> ")) payload_dir = "/home/kenroku/Pictures/Stenography/3.png" out_dir = "/home/kenroku/Pictures/Stenography/out.png" enigma = "hiTELOMERES" terminator = "TELOMERES" if cl == 0: text.encode(payload_dir, out_dir, enigma, terminator) elif cl == 1: text.decode(out_dir, terminator)
def write_passwd(self, passwd): data = [] for user, user_data in passwd.iteritems(): line = u':'.join([user, user_data['password'], user_data['flags']]) data.append(encode(line)) with open(self.path, 'wb') as file: file.write('\n'.join(data) + '\n')
def open(self, url, opts=None, data=None, referer=None, size=-1, add_headers=None): """Open URL and return unicode content""" url = list(urlparse.urlparse(url)) if opts: for key in opts: val = opts[key] if isinstance(val, unicode): opts[key] = encode(val, 'utf-8') query = [urllib.urlencode(opts)] if url[4]: query.append(url[4]) url[4] = u'&'.join(query) realurl = urlparse.urlunparse(url) if self.debug: print 'url = %r' % realurl request = urllib2.Request(realurl, data) if referer: request.add_header(u'Referer', referer) if add_headers: for item in add_headers.items(): request.add_header(*item) response = self.opener.open(request) data = response.read(size) import google if isinstance(response, google.Response): headers = None else: headers = response.headers if headers and headers.get('content-encoding') == 'gzip': data = GzipFile(fileobj=StringIO(data)).read() return encoding.convert(data, headers)
def expandquery(query): if query is None: query = [] elif isinstance(query, basestring): query = urlparse.parse_qsl(query) elif isinstance(query, collections.Mapping): query = list(query.iteritems()) return [(encode(key), map(encode, val if is_sequence(val) else [val])) for key, val in query]
def verifyHash(hash, text): """ check if a hash matches a string """ # un concatenate the stored hash into the hash and the salt salt = hash[:64] # first 64 items in the string hash = hash[64:] # last 64 items in the string # hash the text using the same function and salt, then convert it to hex newHash = hashlib.pbkdf2_hmac('sha512', text.encode('utf-8'), salt.encode('ascii'), 100000) newHash = binascii.hexlify(newHash).decode('ascii') # return true if the new hash matches the old hash return newHash == hash
def hash(text): """ i am using the hashlib library for the pbkdf2 cryptographic hash function which is commonly used for hashing passwords to store in a database """ # generate a random hash using the os library, and then enlarge it using the sha256 function salt = hashlib.sha256(os.urandom(60)).hexdigest().encode('ascii') # hash the text using the generated random salt using the pbkdf2 function pwdhash = hashlib.pbkdf2_hmac('sha512', text.encode('utf-8'), salt, 100000) # convert the text into hexadecimal to make it neater pwdhash = binascii.hexlify(pwdhash) # return the hashed text with the salt concatenated to it, encoded in ascii return (salt + pwdhash).decode('ascii')
def parse_line(line): # Parse line from csv filename, sentence, duration = line.decode('ascii').split('\t') # Audio file wav_path = os.path.join(hyperparams.dataset_path, filename + '.wav') wave = audio.read_audio(wav_path, hyperparams.sample_rate) audio_length = wave.shape[0] / hyperparams.sample_rate # Calculate spectrum mel, linear = audio.spectrogram(hyperparams, wave) # Encode sentence tokens = text.encode(sentence) return mel.T, linear.T, tokens, np.int32( tokens.size), np.float32(audio_length)
def synth(): tokens_ph = tf.placeholder(tf.int32, [None], "tokens_ph") tokens_op = tf.expand_dims(tokens_ph, 0) token_lengths = tf.expand_dims(tf.shape(tokens_ph)[0], 0) tacotron = model.Model(hyperparams, is_training=False, inputs=tokens_op, input_lengths=token_lengths) melspectrum_op = tacotron.decoder.mel_outputs spectrum_op = tacotron.decoder.linear_outputs alignments_op = tacotron.decoder.alignments saver = tf.train.Saver() with tf.Session() as sess: restore_path = input('Restore path: ') saver.restore(sess, restore_path) while True: sentence = input('Input: ') if sentence == '': sentence = "In the beginning God created the heavens and the earth." tokens = text.encode(sentence) melspectrum, spectrum, alignments = sess.run( [melspectrum_op, spectrum_op, alignments_op], {tokens_ph: tokens}) plt.figure() plt.imshow(melspectrum[0]) plt.figure() plt.imshow(spectrum[0]) plt.figure() plt.imshow(alignments[0]) plt.show() signal = audio.reconstruct(hyperparams, spectrum[0].T) audio.write_audio(sentence + ".wav", signal, hyperparams.sample_rate)
def change_password(self, user, plain): passwd = self.get_passwd() if user not in passwd: raise UserNotFound(user) passwd[user]['password'] = self.encrypt(encode(plain)) self.write_passwd(passwd)
def check(self, encrypted, plain): if encrypted == '*': return False salted = b64decode(encode(encrypted)) salt, digest = salted[:4], salted[4:] return digest == self.get_digest(encode(plain), salt)[0]
def encrypt(self, plain): digest, salt = self.get_digest(encode(plain)) return decode(b64encode(salt + digest))
def write(self, data): if not isinstance(data, str): data = encode(data, self.encoding) self.stream.write(data) self.flush()