Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --=== Variables ===--
- local filePath = "save.pass"
- local settings = {
- back = colors.black,
- text = colors.white
- }
- local w,h = term.getSize()
- os.loadAPI("aes")
- --=== Functions ===--
- local function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function scrollRead(x,y,nLength,insertText) --This is a simple scrolling-read function I made
- if insertText then
- insertText = tostring(insertText)
- cPos = #insertText+1
- cInput = insertText
- else
- cPos = 1
- cInput = ""
- end
- term.setCursorBlink(true)
- while true do
- term.setCursorPos(x,y)
- term.write(string.rep(" ",nLength))
- term.setCursorPos(x,y)
- if string.len(cInput) > nLength-1 then
- term.write(string.sub(cInput,(nLength-1)*-1))
- else
- term.write(cInput)
- end
- if cPos > nLength-1 then
- term.setCursorPos(x+nLength-1,y)
- else
- term.setCursorPos(x+cPos-1,y)
- end
- local event,p1 = os.pullEvent()
- if event == "char" then
- cInput = string.sub(cInput,1,cPos)..p1..string.sub(cInput,cPos+1)
- cPos = cPos + 1
- elseif event == "key" then
- if p1 == keys.enter then
- break
- elseif p1 == keys.backspace then
- if cPos > 1 then
- cInput = string.sub(cInput,1,cPos-2)..string.sub(cInput,cPos)
- cPos = cPos - 1
- end
- elseif p1 == keys["end"] then
- cPos = string.len(cInput)+1
- end
- end
- end
- term.setCursorBlink(false)
- return cInput
- end
- function printC(text,y,screen)--Prints text centered at y on screen (term or monitor)
- if not text then error("expected string,number",2) end
- y = tonumber(y)
- if not y then error("expected string,number",2) end
- screen = screen or term
- local tLenght = #tostring(text)
- local sStart = math.ceil(w/2-tLenght/2)
- local sEnd = sStart + tLenght
- screen.setCursorPos(sStart,y)
- screen.write(text)
- return sStart,sEnd
- end
- --=== Program ===--
- term.setBackgroundColor(settings.back)
- clear()
- term.setTextColor(settings.text)
- printC("Welcome to Password Encrypter",2)
- --local hasBeenOpened = false
- --if fs.exists(filePath) then -- Was likely used before, get password
- -- printC("Enter master password",5)
- -- local pass = scrollRead(14,6,10)
- --end
- local continue = true
- while continue do
- printC("Enter a key:",5)
- printC("Enter a secret:",8)
- local key = scrollRead(17,6,17)
- local input = scrollRead(17,9,17)
- printC("Preforming Calculations...",h)
- local enc = aes.encrypt(key,input)
- local f = fs.open(filePath,"wb")
- for i = 1, #enc do
- local cur = string.sub(enc,i,i)
- if cur == "\n" then error("newline Detected!") end
- f.write(string.byte(cur))
- end
- f.close()
- local f2 = fs.open(filePath,"rb")
- local dec = ""
- for byte in f2.read do
- dec = dec..string.char(byte)
- end
- f2.close()
- dec = aes.decrypt(key,dec)
- clear()
- printC("Key:",2)
- printC(key,3)
- printC("Secret",5)
- printC(input,6)
- printC("Encrypted:",8)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- printC(enc,9)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- printC("Decrypted:",11)
- printC(dec,12)
- printC("Press 'Enter' to continue",h)
- repeat
- local event,tKey = os.pullEvent("key")
- until tKey == keys.enter
- clear()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement