Pastebin for program 4: http://pastebin.com/gai9NPjN
Current Completed Programs: 4
A keycard lock, very basic, not safe.
Spoiler
-- THIS IS A KEYCARD LOCK
-- Please edit the parts below to what you want
local pass = "password" -- Change password to the password you want
local door = "bleep" -- Change to the code you want to open the door
local diskdrive = "left" -- Change to side disk drive is on
local passright = "back" -- Change to side you want to be activated when pass is inputed.
local doorright = "right" -- Change to side you want to be activated when door is inputed.
--DO NOT EDIT BELOW THIS LINE
function main()
term.clear()
term.setCursorPos(1, 1)
if disk.isPresent(diskdrive) == true then
label = disk.getLabel(diskdrive)
if disk.hasData(diskdrive) == true then
if label == pass then
password()
elseif label == door then
gate()
else
incorrect()
end
else
incorrect()
end
else
print("Please insert a Disk")
while true do
event, param1 = os.pullEvent()
if event == "disk" then
main()
end
if event == "char" and param1 == "c" then
nData()
end
end
end
end
function password()
term.clear()
term.setCursorPos(1,1)
print("Disk accepted, access granted")
sleep(1)
disk.eject(diskdrive)
print("Please take your disk")
rs.setOutput(passright,true)
sleep(10)
os.shutdown()
end
function gate()
term.clear()
term.setCursorPos(1,1)
print ("Disk accepted, access granted")
sleep(1)
disk.eject(diskdrive)
print("Please take your disk")
rs.setOutput(doorright,true)
sleep(10)
os.shutdown()
end
function incorrect()
term.clear()
term.setCursorPos(1,1)
print("Disk not recognized, access denied")
sleep(3)
disk.eject(diskdrive)
main()
end
function nData()
print("Credits:")
print("Of course, Computercraft by Dan200")
print("Original script: Mougli123")
print("Editer: Dragon53535")
sleep(10)
term.clear()
term.setCursorPos(1,1)
main()
end
main()
The master computer code to put the passwords on the keycards
Spoiler
--Edit these to the codes you put on your lock
local door = "bleep"
local pass = "password"
--DO NOT EDIT BELOW THIS LINE
function main()
door = "bleep"
pass = "password"
print("1: door")
print("2: gate")
input = io.read()
write("> ")
if input == "1" then
disk.setLabel("left",door)
sleep(2)
os.shutdown()
elseif input == "2" then
disk.setLabel("left",pass)
sleep(2)
os.shutdown()
end
end
main()
Wireless server to type commands onto screen, run other programs, and play music
Spoiler
--Please edit the locals below this to what is needed.
local serverID = 0 -- ID of the computer you will be using to command this computer.
local sSide = "back" --What side monitor is on.
local clear = "clear" -- What you want to say to clear screen.
local command = "command" -- What you want to say to enter command mode.
local music = "music" -- What you want to say to turn on music in adjacent disk drive.
local drive = "right" -- What side disk drive is on.
local exit = "exit" -- What you want to say to leave command mode.
local errorkey = "r" -- What key you would like to press to reboot the machine.
local modem = "left" -- The side the wireless modem is on.
--DO NOT EDIT BELOW THIS LINE
local mon = peripheral.wrap(sSide)
function main()
if not mon then
print("No monitor on ", sSide)
return
elseif mon then
main2()
end
end
function main2()
mon.setCursorPos(1,1)
term.redirect(mon)
while true do
rednet.open(modem)
event, id, msg = os.pullEvent()
if event == "rednet_message" then
if id == serverID then
if msg == clear then
mon.clear()
mon.setCursorPos(1,1)
elseif msg == command then
rom()
elseif msg == music then
disk.playAudio(drive)
else
print(msg)
end
end
elseif event == "char" and id == errorkey then
error()
end
end
end
function rom()
while true do
local id, msg = rednet.receive()
if id == serverID then
if msg == exit then
main2()
else shell.run(msg)
end
end
end
end
main()
New Username and Password computer with createable usernames and passwords, as well as ranks.
If you want me to edit this program to suit your needs, just send me a PM over the forums with details of what it needs.
Credit to GravityScore for his SHA256 hashing
Spoiler
local doorside = "right" -- Set to the side your door is on.
local oldPull = os.pullEvent;
os.pullEvent=os.pullEventRaw;
local phil = {}
local MOD = 2^32
local MODM = MOD-1
local function memoize(f)
local mt = {}
local t = setmetatable({}, mt)
function mt:__index(k)
local v = f(k)
t[k] = v
return v
end
return t
end
local function make_bitop_uncached(t, m)
local function bitop(a, B)/>/>/>/>/>/>/>
local res,p = 0,1
while a ~= 0 and b ~= 0 do
local am, bm = a % m, b % m
res = res + t[am][bm] * p
a = (a - am) / m
b = (b - bm) / m
p = p*m
end
res = res + (a + B)/>/>/>/>/>/>/> * p
return res
end
return bitop
end
local function make_bitop(t)
local op1 = make_bitop_uncached(t,2^1)
local op2 = memoize(function(a) return memoize(function(B)/>/>/>/>/>/>/> return op1(a, B)/>/>/>/>/>/>/> end) end)
return make_bitop_uncached(op2, 2 ^ (t.n or 1))
end
local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})
local function bxor(a, b, c, ...)
local z = nil
if b then
a = a % MOD
b = b % MOD
z = bxor1(a, B)/>/>/>/>/>/>/>
if c then z = bxor(z, c, ...) end
return z
elseif a then return a % MOD
else return 0 end
end
local function band(a, b, c, ...)
local z
if b then
a = a % MOD
b = b % MOD
z = ((a + B)/>/>/>/>/>/>/> - bxor1(a,B)/>/>/>/>/>/>/>) / 2
if c then z = bit32_band(z, c, ...) end
return z
elseif a then return a % MOD
else return MODM end
end
local function bnot(x) return (-1 - x) % MOD end
local function rshift1(a, disp)
if disp < 0 then return lshift(a,-disp) end
return math.floor(a % 2 ^ 32 / 2 ^ disp)
end
local function rshift(x, disp)
if disp > 31 or disp < -31 then return 0 end
return rshift1(x % MOD, disp)
end
local function lshift(a, disp)
if disp < 0 then return rshift(a,-disp) end
return (a * 2 ^ disp) % 2 ^ 32
end
local function rrotate(x, disp)
x = x % MOD
disp = disp % 32
local low = band(x, 2 ^ disp - 1)
return rshift(x, disp) + lshift(low, 32 - disp)
end
local k = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
}
local function str2hexa(s)
return (string.gsub(s, ".", function(c) return string.format("%02x", string.byte(c)) end))
end
local function num2s(l, n)
local s = ""
for i = 1, n do
local rem = l % 256
s = string.char(rem) .. s
l = (l - rem) / 256
end
return s
end
local function s232num(s, i)
local n = 0
for i = i, i + 3 do n = n*256 + string.byte(s, i) end
return n
end
local function preproc(msg, len)
local extra = 64 - ((len + 9) % 64)
len = num2s(8 * len, 8)
msg = msg .. "\128" .. string.rep("\0", extra) .. len
assert(#msg % 64 == 0)
return msg
end
local function initH256(H)
H[1] = 0x6a09e667
H[2] = 0xbb67ae85
H[3] = 0x3c6ef372
H[4] = 0xa54ff53a
H[5] = 0x510e527f
H[6] = 0x9b05688c
H[7] = 0x1f83d9ab
H[8] = 0x5be0cd19
return H
end
local function digestblock(msg, i, H)
local w = {}
for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end
for j = 17, 64 do
local v = w[j - 15]
local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))
v = w[j - 2]
w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))
end
local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]
for i = 1, 64 do
local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))
local maj = bxor(band(a, B)/>/>/>/>/>/>/>, band(a, c), band(b, c))
local t2 = s0 + maj
local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))
local ch = bxor (band(e, f), band(bnot(e), g))
local t1 = h + s1 + ch + k[i] + w[i]
h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2
end
H[1] = band(H[1] + a)
H[2] = band(H[2] + B)/>/>/>/>/>/>/>
H[3] = band(H[3] + c)
H[4] = band(H[4] + d)
H[5] = band(H[5] + e)
H[6] = band(H[6] + f)
H[7] = band(H[7] + g)
H[8] = band(H[8] + h)
end
local function sha256(msg)
msg = preproc(msg, #msg)
local H = initH256({})
for i = 1, #msg, 64 do digestblock(msg, i, H) end
return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
end
function Bob()
term.clear()
term.setCursorPos(1,1)
print("1. Login")
write("2. New User?")
while true do
local event, spock = os.pullEvent ("char")
if spock == "1" then
Login()
elseif spock == "2" then
Newguy()
end
end
end
function Normalperson()
term.clear()
term.setCursorPos(1,1)
print("Door opened")
rs.setOutput(doorside,true)
sleep(3)
rs.setOutput(doorside,false)
Bob()
end
function Login()
term.clear()
term.setCursorPos(1,1)
print("Enter Username and Password. Leave blank to cancel.")
print("Username: ")
write("Password: ")
term.setCursorPos(11,2)
chicken = read()
term.setCursorPos(11,3)
passworded = read("*")
if fs.exists("Users/1"..chicken) == true then
file = fs.open("Users/1"..chicken, "r")
local fileData = {}
local line = file.readLine()
repeat
table.insert(fileData,line)
line = file.readLine()
until line == nil
file.close()
local hashData = sha256(passworded)
if hashData == fileData[1] then
if fileData[2] == "Rookie" then
print("You do not have sufficient permissions.")
sleep(2)
Bob()
elseif fileData[2] == "Administrator" then
Checkstartup()
elseif fileData[2] == "Regular" then
Normalperson()
elseif fileData[2] == "Denied" then
fs.delete("Users/1"..chicken)
print("Your account was not accepted, please ask the Administrator in person if you believe this to be a mistake.")
sleep(7.5)
Bob()
elseif fileData[2] == "Banned" then
print("Your account was banned by the admin.")
sleep(4)
Bob()
end
elseif fileData[1] == "ReTurnToBob" then
Bob()
else
print("Username and/or Password are incorrect.")
sleep(2)
Login()
end
else
print("Username and/or Password are incorrect")
sleep(2)
Login()
end
end
function Newguy()
if fs.exists("Users/") == false then
Newadmin()
elseif fs.exists("Users/") == true then
Register()
end
end
function Newadmin()
fs.makeDir("Users")
local bob = fs.open("Users/Newuserschecklist","w")
bob.writeLine("la")
bob.close()
local bobdole = fs.open("Users/1","a")
bobdole.writeLine("ReTurnToBob")
bobdole.close()
term.clear()
term.setCursorPos(1,1)
print("No Users detected. Enter Admin login. You must complete Admin signup or program will not function.")
print("Username: ")
print("Password: ")
term.setCursorPos(11,3)
adminuser = read()
term.setCursorPos(11,4)
adminpass = read("*")
local holdup = sha256(adminpass)
local file = fs.open("Users/1"..adminuser,"a")
file.writeLine(holdup)
file.writeLine("Administrator")
file.close()
print("Registered new Admin")
sleep(4)
Bob()
end
function Register()
local LeaveFunction = ""
term.clear()
term.setCursorPos(1,1)
print("New user setup, please enter new username and pass.")
print("Username: ")
print("Password: ")
term.setCursorPos(11,2)
newuser = read()
term.setCursorPos(11,3)
newpass = read("*")
if newuser = LeaveFunction then
Bob()
elseif fs.exists("Users/1"..newuser) == true then
print("Username already exists, please try again.")
sleep(2.5)
Register()
else
local halla = sha256(newpass)
local file = fs.open("Users/1"..newuser,"a")
file.writeLine(halla)
file.writeLine("Rookie")
file.close()
local filed = fs.open("Users/Newuserschecklist","a")
filed.writeLine(newuser)
filed.close()
print("New user made, please wait for admin authentication before logging in.")
sleep(5)
Bob()
end
end
function Checkstartup()
local jimbo = shell.getRunningProgram()
if jimbo == "startup" then
Adminmenu()
elseif jimbo ~= "startup" then
term.clear()
term.setCursorPos(1,1)
print("The program will not open on startup. Would you like it to?")
print("1. Yes")
print("2. No")
while true do
local jimm, joo = os.pullEvent("char")
if joo == "1" then
fs.move(jimbo,"startup")
Adminmenu()
elseif joo == "2" then
Adminmenu()
end
end
end
end
function Adminmenu()
term.clear()
term.setCursorPos(1,1)
print("Admin Menu.")
print("1. Edit Program")
print("2. New Users")
print("3. Edit User Ranks")
print("4. Exit Program")
print("5. Normal Menu")
print("6. Logout")
while true do
local tit, pie = os.pullEvent ("char")
if pie == "1" then
local steve = shell.getRunningProgram()
shell.run("edit",steve)
print("Reloading program")\
sleep(1.5)
shell.run(steve)
elseif pie == "2" then
Newuseroption()
elseif pie == "3" then
Admindisclaimer()
elseif pie == "4" then
error()
elseif pie == "5" then
Normalperson()
elseif pie == "6" then
Bob()
end
end
end
function Newuseroption()
term.clear()
term.setCursorPos(1,1)
print("Are you sure you want to view the new users? You must complete every user or the rest will be deleted from the database.")
print("1. Yes")
print("2. No")
while true do
local even, tat = os.pullEvent("char")
if tat == "1" then
Newuserschecklist()
elseif tat == "2" then
Adminmenu()
end
end
end
function Newuserschecklist()
local bob = fs.open("Users/Newuserschecklist","r")
local filebob = {}
local tag = bob.readLine()
table.insert(filebob,tag)
z = 2
tag = bob.readLine()
if tag == nil then
print("No new users.")
sleep(2.5)
Adminmenu()
else
repeat
term.clear()
term.setCursorPos(1,1)
table.insert(filebob,tag)
local alpha = filebob[z]
print(alpha)
print("1. Accept")
print("2. Decline")
local newbob = fs.open("Users/1"..alpha,"r")
local file = newbob.readLine()
local test = {}
while file do
table.insert(test,file)
file = newbob.readLine()
end
newbob.close()
while true do
local sir, henry = os.pullEvent ("char")
if henry == "1" then
local chick = fs.open("Users/1"..alpha,"w")
chick.writeLine(test[1])
chick.writeLine("Regular")
chick.close()
break
elseif henry == "2" then
local chick = fs.open("Users/1"..alpha,"w")
chick.writeLine(test[1])
chick.writeLine("Denied")
chick.close()
break
end
end
z = z + 1
tag = bob.readLine()
until tag == nil
bob.close()
local guess = fs.open("Users/Newuserschecklist","w")
guess.writeLine("la")
guess.close()
Bob()
end
end
function Currentusers()
local tester = fs.list("Users")
local jim = {}
for a, p in ipairs(tester) do
table.insert(jim,a,p)
end
local o = 0
local x = 0
local y = 7
local z = 1
local yay = {}
repeat
yay = {}
term.clear()
term.setCursorPos(1,1)
y=y*z
local a = 0
repeat
a=a+1
x=x+1
local bob = tostring(a)
if jim[x] == nil then
break
else
table.insert(yay,jim[x])
print(a..". "..jim[x])
end
until a == y
print("8. Previous")
print("9. Next")
print("0. Exit")
while true do
local event, para = os.pullEvent("char")
if para == "1" then
table.insert(phil,yay[1])
hell()
elseif para == "2" then
if yay[2] ~= nil then
table.insert(phil,yay[2])
hell()
elseif yay[2] == nil then
print("File doesn't exist")
end
elseif para == "3" then
if yay[3] ~= nil then
table.insert(phil,yay[3])
hell()
elseif yay[3] == nil then
print("File doesn't exist")
end
elseif para == "4" then
if yay[4] ~= nil then
table.insert(phil,yay[4])
hell()
elseif yay[4] == nil then
print("File doesn't exist")
end
elseif para == "5" then
if yay[5] ~= nil then
table.insert(phil,yay[5])
hell()
elseif yay[5] == nil then
print("File doesn't exist")
end
elseif para == "6" then
if yay[6] ~= nil then
table.insert(phil,yay[6])
hell()
elseif yay[6] == nil then
print("File doesn't exist")
end
elseif para == "7" then
if yay[7] ~= nil then
table.insert(phil,yay[7])
hell()
elseif yay[7] == nil then
print("File doesn't exist")
end
elseif para == "8" then
if o == 0 then
print("Cannot go back")
elseif o ~= 0 then
o = o-2
local j = o+1
x=7*j
break
end
elseif para == "9" then
if jim[x] == nil then
print("Cannot go forward")
elseif jim[x] ~= nil then
break
end
elseif para == "0" then
Adminmenu()
end
end
o=o+1
until nil
end
function hell()
term.clear()
term.setCursorPos(1,1)
local jimmy = fs.open("Users/"..phil[1],"r")
local colin = {}
local liner = jimmy.readLine()
repeat
table.insert(colin,liner)
liner = jimmy.readLine()
until liner == nil
jimmy.close()
print("Choose rank of "..phil[1].. ". Currently rank: "..colin[2])
print("1. Admin")
print("2. Regular")
print("3. Banned")
print("4. Exit")
while true do
local joe, jon = os.pullEvent("char")
if jon == "1" then
local who = fs.open("Users/"..phil[1],"w")
who.writeLine(colin[1])
who.writeLine("Administrator")
who.close()
table.remove(phil,1)
Adminmenu()
elseif jon == "2" then
local who = fs.open("Users/"..phil[1],"w")
who.writeLine(colin[1])
who.writeLine("Regular")
who.close()
table.remove(phil,1)
Adminmenu()
elseif jon == "3" then
local who = fs.open("Users/"..phil[1],"w")
who.writeLine(colin[1])
who.writeLine("Banned")
who.close()
table.remove(phil,1)
Adminmenu()
elseif jon == "4" then
Adminmenu()
end
end
end
function Admindisclaimer()
term.clear()
term.setCursorPos(1,1)
print("Please do not edit the files, named: 1, and Newuserchecklist, those are used for other functions and will not work if edited")
sleep(5)
Currentusers()
end
Bob()
os.pullEvent=oldPull;
Hey i'm looking for inspiration, PM with requests! Please be specific on the function if it's to do something specific.