Advertisement
DOGGYWOOF

lock

Jan 6th, 2024 (edited)
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. local cipher = {
  2. A = "X",
  3. B = "Y",
  4. -- Add more substitutions for each character as needed
  5. }
  6.  
  7. function encryptPassword(password)
  8. local encrypted = ""
  9. for i = 1, #password do
  10. local char = string.upper(string.sub(password, i, i))
  11. if cipher[char] then
  12. encrypted = encrypted .. cipher[char]
  13. else
  14. encrypted = encrypted .. char
  15. end
  16. end
  17. return encrypted
  18. end
  19.  
  20. function decryptPassword(encrypted)
  21. local decrypted = ""
  22. for i = 1, #encrypted do
  23. local char = string.upper(string.sub(encrypted, i, i))
  24. local found = false
  25. for key, value in pairs(cipher) do
  26. if value == char then
  27. decrypted = decrypted .. key
  28. found = true
  29. break
  30. end
  31. end
  32. if not found then
  33. decrypted = decrypted .. char
  34. end
  35. end
  36. return decrypted
  37. end
  38.  
  39. local doorSide = "right" -- Side of the door
  40.  
  41. function unlockDoor()
  42. redstone.setOutput(doorSide, true) -- Unlock the door (if it accepts redstone)
  43. print("Door unlocked on the right side.")
  44. end
  45.  
  46. function lockDoor()
  47. redstone.setOutput(doorSide, false) -- Lock the door (if it accepts redstone)
  48. print("Door locked on the right side.")
  49. end
  50.  
  51. -- Usage example
  52. local password = "MySecretPassword"
  53. local encryptedPassword = encryptPassword(password)
  54. print("Encrypted Password:", encryptedPassword)
  55.  
  56. -- Assuming the user inputs the correct password
  57. local userInput = io.read()
  58. if userInput == encryptedPassword then
  59. unlockDoor() -- Unlock the door on the right side
  60. else
  61. print("Incorrect password.")
  62. end
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement