Esempio n. 1
0
def file_entry():
    """ takes entry of website, username and password 
    from a txt file
    """
    print("Note: Insert file in txt format")
    fname = input("Enter location of file: ")
    if (len(fname) < 1):
        fname = settings.passlist
    fh = open(fname)
    entry_count = 0
    w, u, p = (list() for i in range(3))
    for line in fh:
        if (line.startswith('Website:  ')):
            pieces = line.split()
            w.append(pieces[1].lower())
        if (line.startswith('Username:  '******'Password:  ')):
            pieces = line.split()
            p.append(pieces[1])

    for entry in range(len(w)):
        record = get_data(w[entry])
        if record is None:
            password = encrypt(p[entry])
            insert_data(w[entry], u[entry], password)
            entry_count += 1
        else:
            print("{} present already \n".format(w[entry]))

    print("Added {} entry successfully \n".format(entry_count))
Esempio n. 2
0
def encrypt_file(filename):
    key = input(
        "Enter secret key, remember this key as it will not be saved: ")
    chunk = 16 * 1024
    with open(filename, "r") as r:
        while True:
            data = r.read(chunk)
            if len(data) == 0:
                break
            with open(filename, "w") as w:
                w.write(encrypt(data, key))
Esempio n. 3
0
def make_tree(files, hashes):
    # print(files)
    # print(hashes)
    path = dict()
    file_count = 0
    # hashes = []
    for file_name in files:
        file_hash = hashes[file_count]
        # hashes.append(file_hash)
        path[file_name] = {'current_hash': file_hash, 'path': ''}
        file_count += 1

    height = ceil(log2(file_count))
    hashes = [hashes.copy()]
    for i in range(height):
        hash_count = len(hashes[i])
        row = []
        for j in range(0, hash_count, 2):
            if j < hash_count - 1:
                combined_hash = hash_string(
                    combine(hashes[i][j], hashes[i][j + 1]))
                path = update_path(path, hashes[i][j], hashes[i][j + 1],
                                   combined_hash)
                row.append(combined_hash)
            elif j == hash_count - 1:
                row.append(hashes[i][j])
        hashes.append(row)

    # for row in hashes:
    #     print(row)
    # save_path(path)

    results = dict()
    results['Files Path'] = {}

    for file_name in path:
        results['Files Path'][file_name] = path[file_name]['path']

    root_hash = hashes[-1][-1]
    # print(root_hash)
    encrypted_hash = encrypt(root_hash)
    # print(encrypted_hash)
    tx_details = make_transaction(encrypted_hash)

    results['Transaction'] = tx_details

    return results
Esempio n. 4
0
def terminal_entry():
    """ takes entry of website, username and password 
    from the terminal. Used when entry has to be done manually
    """
    trigger = 1
    while (trigger == 1):
        print("Enter Website, Username and Password\n")
        w = get_input()
        record = get_data(w)

        if record is None:
            u = input("Username: "******"Website already exists")

        print("\n Press 1 to insert again else 0\n")
        trigger = int(input("1 or 0: "))
Esempio n. 5
0
def update_entry():
    """ used to update password and username of a existing website
    """
    print("Enter the website you want to update into\n")
    w = get_input()

    record = get_data(w)
    if record is None:
        print("Website name doesn't exits!")
        val = int(input("Press 1 to enter the website else 0: "))
        if (val == 1):
            terminal_entry()
    else:
        print("Enter the Username and New Password")
        u = input("Username: "******"\nUpdated entry!\n")
        display_data(0, w)
    except:
        print("Website doesn't exist in db")
Esempio n. 6
0
def Encode(input_path,output_path,message,key):
	#encrypting the message
	encrypted = encrypt_decrypt.encrypt(message , key)
	#steganograph the image
	Steganography.encode(input_path, output_path, encrypted)
 def test_encrypt(self):
     self.assertEqual(encrypt(self.input_message, self.encrypt_codes),
                      self.output_message, "Encryption failed")