Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to create a new profile (already exists)
- local function createProfile()
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.cyan)
- print("Enter a username for the new profile:")
- term.setTextColor(colors.white)
- local username = read()
- local profilePath = "./dogchat/profiles/" .. username
- if fileExists(profilePath) then
- term.setTextColor(colors.red)
- print("Profile already exists.")
- term.setTextColor(colors.white)
- return
- end
- term.setTextColor(colors.cyan)
- print("Enter a password for the profile:")
- term.setTextColor(colors.white)
- local password = read("*")
- local encryptionKey = downloadOrCreateKey()
- local hashedPassword = xorEncryptDecrypt(password, encryptionKey)
- fs.makeDir(profilePath)
- local passwordFile = fs.open(profilePath .. "/password.txt", "w")
- passwordFile.write(hashedPassword)
- passwordFile.close()
- term.setTextColor(colors.green)
- print("Profile created successfully.")
- term.setTextColor(colors.white)
- end
- -- Function to read inbox and decrypt messages
- local function readInbox(username)
- local profilePath = "./dogchat/profiles/" .. username
- local inboxPath = profilePath .. "/inbox.txt"
- if not fileExists(inboxPath) then
- term.setTextColor(colors.red)
- print("No messages found.")
- term.setTextColor(colors.white)
- return
- end
- -- Ask for password to decrypt messages
- term.setTextColor(colors.cyan)
- print("Enter your password to access the inbox:")
- term.setTextColor(colors.white)
- local password = read("*")
- local encryptionKey = downloadOrCreateKey()
- local passwordFile = fs.open(profilePath .. "/password.txt", "r")
- local storedPassword = passwordFile.readAll()
- passwordFile.close()
- -- Validate password
- if xorEncryptDecrypt(password, encryptionKey) ~= storedPassword then
- term.setTextColor(colors.red)
- print("Incorrect password.")
- term.setTextColor(colors.white)
- return
- end
- -- Decrypt the inbox
- local inboxFile = fs.open(inboxPath, "r")
- local encryptedMessages = inboxFile.readAll()
- inboxFile.close()
- local decryptedMessages = xorEncryptDecrypt(encryptedMessages, encryptionKey)
- term.setTextColor(colors.cyan)
- print("Inbox Messages:")
- term.setTextColor(colors.white)
- print(decryptedMessages)
- end
- -- Function to send a message to a profile's inbox
- local function sendMessageToInbox(receiverUsername, message)
- local profilePath = "./dogchat/profiles/" .. receiverUsername
- local inboxPath = profilePath .. "/inbox.txt"
- local encryptionKey = downloadOrCreateKey()
- -- Encrypt the message before sending
- local encryptedMessage = xorEncryptDecrypt(message, encryptionKey)
- -- Write the encrypted message to the inbox
- fs.makeDir(profilePath) -- Ensure the inbox exists
- local inboxFile = fs.open(inboxPath, "a") -- Open inbox in append mode
- inboxFile.write(encryptedMessage .. "\n")
- inboxFile.close()
- term.setTextColor(colors.green)
- print("Message sent successfully.")
- term.setTextColor(colors.white)
- end
- -- Function to delete a profile (already exists)
- local function deleteProfile()
- -- Same code as you provided earlier
- end
- -- Function to show settings menu (already exists)
- local function settingsMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("Settings Menu:")
- print("1. Create New Profile")
- print("2. Delete Profile")
- print("3. Exit Settings")
- print("4. Read Inbox")
- print("5. Send Message")
- local choice = read()
- if choice == "1" then
- createProfile()
- elseif choice == "2" then
- deleteProfile()
- elseif choice == "3" then
- return
- elseif choice == "4" then
- term.setTextColor(colors.cyan)
- print("Enter the username to read inbox:")
- term.setTextColor(colors.white)
- local username = read()
- readInbox(username)
- elseif choice == "5" then
- term.setTextColor(colors.cyan)
- print("Enter the username to send a message to:")
- term.setTextColor(colors.white)
- local username = read()
- term.setTextColor(colors.cyan)
- print("Enter the message to send:")
- term.setTextColor(colors.white)
- local message = read()
- sendMessageToInbox(username, message)
- else
- term.setTextColor(colors.red)
- print("Invalid choice.")
- term.setTextColor(colors.white)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement