#๐Ÿ”’ encryption

7 messages ยท Page 1 of 1 (latest)

merry socketBOT
#

@small sequoia

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

small sequoia
#

the code is

#
import os.path
from cryptography.fernet import Fernet
filename = "accounts.txt"

def generate_key():
  key = Fernet.generate_key()
  # Save the key securely, preferably not in the same script
  with open('secret.key', 'wb') as key_file:
    key_file.write(key)
  return key

def encrypt_file(filename, key):
  fernet = Fernet(key)
  with open(filename, 'rb') as file:
    original_data = file.read()
  encrypted_data = fernet.encrypt(original_data)
  with open(filename + '.encrypted', 'wb') as encrypted_file:
    encrypted_file.write(encrypted_data)

def decrypt_file(filename, key):
  fernet = Fernet(key)
  with open(filename, 'rb') as encrypted_file:
    encrypted_data = encrypted_file.read()
  decrypted_data = fernet.decrypt(encrypted_data)
  with open(filename[:-len('.encrypted')], 'wb') as decrypted_file:
    decrypted_file.write(decrypted_data)

def createAccount(username, passwrd, file):
    file.write(f"{username} ; {passwrd}\n")

def promptUser():
    usrname = input("Username: ")
    passwrd = input("Password: ")
    with open("accounts.txt", "a") as file:  # Open for appending
        createAccount(usrname, passwrd, file)


promptUser()
#

im having trouble trying to open the file to append more data

merry socketBOT
#

@small sequoia

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ encryption