Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Doggy OS Encryption Password Setup
- -- Function to generate a key for encryption and decryption
- local function generateKey()
- local chars = {}
- for i = 32, 126 do -- ASCII range for printable characters
- table.insert(chars, string.char(i))
- end
- local key = {}
- while #chars > 0 do
- local index = math.random(#chars)
- table.insert(key, table.remove(chars, index))
- end
- return table.concat(key)
- end
- -- Function to create a map from a key
- local function createMap(key)
- local map = {}
- for i = 32, 126 do
- map[string.char(i)] = key:sub(i - 31, i - 31)
- end
- return map
- end
- -- Function to encrypt text using a key
- local function encrypt(text, key)
- local map = createMap(key)
- local encrypted = {}
- for i = 1, #text do
- local char = text:sub(i, i)
- table.insert(encrypted, map[char] or char)
- end
- return table.concat(encrypted)
- end
- -- Function to save the key to a file
- local function saveKeyToFile(key)
- local randomNumber = math.random(1, 1000)
- local fileName = "key" .. randomNumber .. ".txt"
- local file = io.open(fileName, "w")
- file:write(key)
- file:close()
- return fileName
- end
- -- Function to set or reset the encryption password
- local function setPassword()
- term.clear()
- term.setCursorPos(1, 1)
- print("Doggy OS Encryption Password Setup")
- print()
- print("Enter new password:")
- local newPassword = read("*")
- -- Generate a new encryption key
- local key = generateKey()
- local encryptedPassword = encrypt(newPassword, key)
- -- Save the encrypted password to a file
- local file = io.open("password.txt", "w")
- file:write(encryptedPassword)
- file:close()
- -- Save the encryption key to a file
- local keyFileName = saveKeyToFile(key)
- print("Password set successfully.")
- print("Encryption key saved to file: " .. keyFileName)
- print("Press ENTER to continue.")
- io.read() -- Wait for user to press enter
- end
- -- Main program
- term.clear()
- term.setCursorPos(1, 1)
- print("Doggy OS Encryption Password Setup")
- print()
- -- Check if password file already exists
- if fs.exists("password.txt") then
- print("Password is already set.")
- print("Press ENTER to exit.")
- io.read() -- Wait for user to press enter
- else
- setPassword()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement