def write_object(filename, text, password=None): """write text to a file""" if password: text = encryption.encrypt_text(text, password) f_o = open(filename, 'w') print >>f_o, text f_o.close() return True
def test_full_encrypt_text(self): interrupter = 0 plaintext = tt.get_koan2_plaintext() key = np.array([0, 10, 4, 0, 1, 19, 0, 18, 4, 18, 9, 0, 18]) # FIRFUMFERENFE algorithm = 'Vigenere' reverse_text = False reverse_gematria = False shift_id = 0 interrupter_array = np.asarray(plaintext == interrupter, dtype=int) ct = enc.encrypt_text(plaintext, algorithm, shift_id, reverse_text, reverse_gematria, interrupter, key, interrupter_array) np.testing.assert_array_equal(tt.get_koan2_text(), ct)
def write_object(self, filename, text, password = None): """write text to a db collection""" self.db = self.check_connection() notebookplusuid = self.helper.split_filename(filename) notebook = notebookplusuid[0] uid = notebookplusuid[1] collection = self.db[notebook] title = self.get_title(filename, password) main = text[len(title)+1:] max_title_len = notesapp.GUI.max_title_len.fget('max_title_len') new_title = str(text)[0:max_title_len].split('\n')[0] if password: main = encryption.encrypt_text(main, password) collection.update({'_id': uid}, {"$set": { 'body': main}}) # only set title when really needed; otherwise possible bug with multiple titles if new_title and new_title != title: if password: new_title = encryption.encrypt_text(new_title, password) collection.update({'_id': uid}, {"$set": { 'title': new_title}}) return True
def add_note(self, collection, uid, password): """adds a note with default title to a collection""" if uid == 0: uid = uuid.uuid4() notesapp.GUI.notecount = collection.count()+1 title = notesapp.GUI.initial_notetitle.fget('initial_notetitle') + ( repr(notesapp.GUI.notecount) ) if password: encry_title = encryption.encrypt_text(title, password) collection.insert({'_id': str(uid),'title': encry_title, 'body': '', 'created_at': datetime.now().isoformat(' ')}) else: collection.insert({'_id': str(uid),'title': title, 'body': '', 'created_at': datetime.now().isoformat(' ')}) return (title, uid) # used in get_title
def test_autokey_shift0(self): interrupter = 0 ct_numbers = tt.get_koan2_plaintext() interrupter_array = np.asarray(ct_numbers == interrupter) ciphertext = enc.encrypt_text(plaintext=ct_numbers, algorithm='Autokey', shift_id=0, reverse_text=False, reverse_gematria=False, interrupter=interrupter, key=np.array( [0, 10, 15, 8, 18, 4, 19, 24, 9]), interrupter_array=interrupter_array) hpf.main(algorithm=1, shift_id=0, reversed_text=False, reverse_gematria=False, interrupter=interrupter, ciphertext=ciphertext) df = pd.read_csv('keys.txt', sep=',') self.assertEqual( hpf.translate_to_english(tt.get_koan2_plaintext(), reverse_gematria=False), df.loc[0, 'Message text'])
def send_text_encrypted(text, usocket, session_key): enc_data = encrypt_text(text, session_key) send_data(enc_data, usocket)