Advertisement
DOGGYWOOF

Untitled

Dec 15th, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. -- Function to create a new profile (already exists)
  2. local function createProfile()
  3. term.clear()
  4. term.setCursorPos(1, 1)
  5. term.setTextColor(colors.cyan)
  6. print("Enter a username for the new profile:")
  7. term.setTextColor(colors.white)
  8. local username = read()
  9.  
  10. local profilePath = "./dogchat/profiles/" .. username
  11. if fileExists(profilePath) then
  12. term.setTextColor(colors.red)
  13. print("Profile already exists.")
  14. term.setTextColor(colors.white)
  15. return
  16. end
  17.  
  18. term.setTextColor(colors.cyan)
  19. print("Enter a password for the profile:")
  20. term.setTextColor(colors.white)
  21. local password = read("*")
  22.  
  23. local encryptionKey = downloadOrCreateKey()
  24. local hashedPassword = xorEncryptDecrypt(password, encryptionKey)
  25.  
  26. fs.makeDir(profilePath)
  27. local passwordFile = fs.open(profilePath .. "/password.txt", "w")
  28. passwordFile.write(hashedPassword)
  29. passwordFile.close()
  30.  
  31. term.setTextColor(colors.green)
  32. print("Profile created successfully.")
  33. term.setTextColor(colors.white)
  34. end
  35.  
  36. -- Function to read inbox and decrypt messages
  37. local function readInbox(username)
  38. local profilePath = "./dogchat/profiles/" .. username
  39. local inboxPath = profilePath .. "/inbox.txt"
  40.  
  41. if not fileExists(inboxPath) then
  42. term.setTextColor(colors.red)
  43. print("No messages found.")
  44. term.setTextColor(colors.white)
  45. return
  46. end
  47.  
  48. -- Ask for password to decrypt messages
  49. term.setTextColor(colors.cyan)
  50. print("Enter your password to access the inbox:")
  51. term.setTextColor(colors.white)
  52. local password = read("*")
  53.  
  54. local encryptionKey = downloadOrCreateKey()
  55. local passwordFile = fs.open(profilePath .. "/password.txt", "r")
  56. local storedPassword = passwordFile.readAll()
  57. passwordFile.close()
  58.  
  59. -- Validate password
  60. if xorEncryptDecrypt(password, encryptionKey) ~= storedPassword then
  61. term.setTextColor(colors.red)
  62. print("Incorrect password.")
  63. term.setTextColor(colors.white)
  64. return
  65. end
  66.  
  67. -- Decrypt the inbox
  68. local inboxFile = fs.open(inboxPath, "r")
  69. local encryptedMessages = inboxFile.readAll()
  70. inboxFile.close()
  71.  
  72. local decryptedMessages = xorEncryptDecrypt(encryptedMessages, encryptionKey)
  73.  
  74. term.setTextColor(colors.cyan)
  75. print("Inbox Messages:")
  76. term.setTextColor(colors.white)
  77. print(decryptedMessages)
  78. end
  79.  
  80. -- Function to send a message to a profile's inbox
  81. local function sendMessageToInbox(receiverUsername, message)
  82. local profilePath = "./dogchat/profiles/" .. receiverUsername
  83. local inboxPath = profilePath .. "/inbox.txt"
  84.  
  85. local encryptionKey = downloadOrCreateKey()
  86.  
  87. -- Encrypt the message before sending
  88. local encryptedMessage = xorEncryptDecrypt(message, encryptionKey)
  89.  
  90. -- Write the encrypted message to the inbox
  91. fs.makeDir(profilePath) -- Ensure the inbox exists
  92. local inboxFile = fs.open(inboxPath, "a") -- Open inbox in append mode
  93. inboxFile.write(encryptedMessage .. "\n")
  94. inboxFile.close()
  95.  
  96. term.setTextColor(colors.green)
  97. print("Message sent successfully.")
  98. term.setTextColor(colors.white)
  99. end
  100.  
  101. -- Function to delete a profile (already exists)
  102. local function deleteProfile()
  103. -- Same code as you provided earlier
  104. end
  105.  
  106. -- Function to show settings menu (already exists)
  107. local function settingsMenu()
  108. term.clear()
  109. term.setCursorPos(1, 1)
  110. print("Settings Menu:")
  111. print("1. Create New Profile")
  112. print("2. Delete Profile")
  113. print("3. Exit Settings")
  114. print("4. Read Inbox")
  115. print("5. Send Message")
  116.  
  117. local choice = read()
  118.  
  119. if choice == "1" then
  120. createProfile()
  121. elseif choice == "2" then
  122. deleteProfile()
  123. elseif choice == "3" then
  124. return
  125. elseif choice == "4" then
  126. term.setTextColor(colors.cyan)
  127. print("Enter the username to read inbox:")
  128. term.setTextColor(colors.white)
  129. local username = read()
  130. readInbox(username)
  131. elseif choice == "5" then
  132. term.setTextColor(colors.cyan)
  133. print("Enter the username to send a message to:")
  134. term.setTextColor(colors.white)
  135. local username = read()
  136. term.setTextColor(colors.cyan)
  137. print("Enter the message to send:")
  138. term.setTextColor(colors.white)
  139. local message = read()
  140. sendMessageToInbox(username, message)
  141. else
  142. term.setTextColor(colors.red)
  143. print("Invalid choice.")
  144. term.setTextColor(colors.white)
  145. end
  146. end
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement