Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Security Card API
- local password = "Password for Encryption"
- --You could change this per computer or have it the same...
- --up to you really I would save it somewhere on the computer encrypted
- --so a password is needed when the computer boots up to let anyone with
- --the card through but that might be awkward in multiplayer
- function encrypt(msg,pass)
- -- msg= (32-126)
- local str =""
- local key = 0
- msg= msg:reverse()
- for x = 1, #pass do
- key = key + pass:byte(x)
- end
- key = (key+2)%50
- for x = 1, #msg do
- local ch = string.byte(msg,x)
- ch = ch - key
- if(ch<32)then
- ch = 126 - (32-ch)
- end
- ch = string.char(ch)
- str = str..ch
- end
- return str
- end
- function decrypt(msg,pass)
- -- msg= (32-126)
- local str =""
- local key = 0
- for x = 1, #pass do
- key = key + pass:byte(x)
- end
- key = (key+2)%50
- for x = 1, #msg do
- local ch = 0
- local t = 0
- ch = string.byte(msg,x)+key
- if(ch>126)then
- ch = 32 + (ch-126)
- end
- ch = string.char(ch)
- str = str..ch
- end
- str= str:reverse()
- return str
- end
- function setDiskLevel(side, lvl1, lvl2, psw)
- if fs.exists("disk/level") then
- fs.delete("disk/level")
- end
- local h = fs.open("disk/level", "w")
- h.writeLine("level1:"..encrypt(lvl1,password))
- h.writeLine("level2:"..encrypt(lvl2,password))
- h.writeLine("Password:"..encrypt(psw,password))
- h.close()
- disk.setLabel(side, "Level: "..lvl1.."-"..lvl2.." Card")
- end
- function getDiskLevel(side)
- if fs.exists("disk/level") then
- local h = fs.open("disk/level", "r")
- local lvl1 = decrypt(string.sub(h.readLine(), 8),password)
- local lvl2 = decrypt(string.sub(h.readLine(), 8),password)
- local psw = decrypt(string.sub(h.readLine(), 10),password)
- h.close()
- return lvl1, lvl2, psw
- else
- return false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment