pass = "12345"
enclvl = 0
hash = {{'1','2','3','4'},{'5','6','7','8'}}
patDec = {{'1','2','3','4'},{'5','6','7','8'}}
patSol = "12345678"
maxX = 4
maxY = 2
selI = {1, 1}
strI = ""
lenI = 8
WdLen = 1
menu1 = {"Inbox", "Disk", "Exit"}
menu2 = {"Sent", "Received", "Back"}
menu3 = {"message 1", "Back"}
mess1 = "From : Imef\nTo : Peter\n\nThis is a message."
function menu(x, y, op)
n = table.maxn(op)
pos = 1
stop = false
while stop == false do
term.clear()
term.setCursorPos(1,1)
print("Encryption Level : " .. enclvl)
for i=1,n do
term.setCursorPos(x,y-n/2+i)
if i==pos then
print("> " .. op)
else
print(op)
end
end
e, key = os.pullEvent("key")
if key == 200 then
pos = pos-1
if pos == 0 then pos = n end
end
if key == 208 then
pos = pos+1
if pos == n+1 then pos = 1 end
end
if key == 28 or key == 57 then
stop = true
end
end
return pos
end
function passBreak(p)
a = "abcdefghijklmnopqrstuvwxyz"
for i = 1, string.len(p) do
for j = 1, string.len(a) do
term.clear()
term.setCursorPos(1,1)
print("Calculating...")
print(string.sub(p, 1, i-1) .. string.sub(a,j,j))
sleep(0.05)
end
end
term.clear()
term.setCursorPos(1,1)
print("Password found :")
print(p)
print("")
print("Press any key to continue...")
os.pullEvent("key")
end
function decrypt(lvl, enc)
term.clear()
term.setCursorPos(1,1)
if lvl >= enc then
print("Decrypting...")
sleep(lvl*0.5 + 1)
print("done")
enclvl = 0
else
print("Encryption level too high.")
end
print("Press Any key to continue...")
os.pullEvent("key")
end
function interface()
stpI = false
while stpI == false do
term.clear()
term.setCursorPos(1,1)
print("Pattern Recognition")
for i=1,maxY do
term.setCursorPos(4,3+i)
for j=1,maxX do
if selI[1] == i and selI[2] == j then
write("<" .. hash[j] .. ">")
else
write(" " .. hash[j] .. " ")
end
end
end
term.setCursorPos(1,9)
write("Password : " .. strI)
e, k = os.pullEvent("key")
if k == 200 then selI[1] = selI[1] - 1
elseif k == 208 then selI[1] = selI[1] + 1
elseif k == 203 then selI[2] = selI[2] - 1
elseif k == 205 then selI[2] = selI[2] + 1
end
selI[1] = (selI[1]-1)%maxY + 1
selI[2] = (selI[2]-1)%maxX + 1
if k == 57 or k == 28 then stpI = true end
end
strI = strI .. hash[selI[1]][selI[2]]
term.setCursorPos(1,9)
print("Password : " .. strI)
end
function pattern()
strI = ""
stI = false
while stI == false do
interface()
if string.len(strI) == WdLen*lenI then
stI = true
if strI == patSol then
term.setCursorPos(1,10)
print("Correct!")
sleep(1)
admin()
else
print("Incorrect!")
sleep(1)
end
strI = ""
end
end
end
function patDecode()
term.clear()
term.setCursorPos(1,1)
if hash -= nil then
print("Calculating...")
for j=1,maxY do
term.setCursorPos(3,3+j)
for i=1,maxX do
write("* ")
sleep(0.1)
end
end
for j=1,maxY do
term.setCursorPos(3,3+j)
for i=1,maxX do
write(patDec[j] .. " ")
sleep(1)
end
end
else
print("Can't find pattern...")
end
print("\n\nPress any key to continue")
os.pullEvent("key")
end
function diskCheck(s)
term.clear()
term.setCursorPos(1,1)
print("Searching...")
sleep(0.5)
if disk.isPresent(s) == false then
print("disk drive empty.")
sleep(1)
else
l = disk.getLabel(s)
if l == "Password Breaker" then passBreak(pass)
elseif l == "Decrypter Level 1" then decrypt(1, enclvl)
elseif l == "Decrypter Level 2" then decrypt(2, enclvl)
elseif l == "Decrypter Level 3" then decrypt(3, enclvl)
elseif l == "Pattern Decoder" then patDecode()
else print("Disk empty or corrupt.")
sleep(1)
end
end
end
function showDoc(doc)
term.clear()
term.setCursorPos(1,1)
print(doc)
print("")
print("Press any key to continue...")
os.pullEvent("key")
end
function ReceivedBox()
term.clear()
term.setCursorPos(1,1)
print("This box is empty...\n\nPress any key to continue...")
os.pullEvent("key")
end
function SentBox()
stpB = false
while stpB == false do
ch = menu(1, 4, menu3)
term.clear()
term.setCursorPos(1,1)
if ch == 1 then
showDoc(mess1)
else
stpB = true
end
end
end
function admin()
stp = false
while stp == false do
ch = menu(20, 8, menu2)
term.clear()
term.setCursorPos(1,1)
if ch == 1 then
SentBox()
elseif ch == 2 then
ReceivedBox()
else
stp = true
end
end
end
st = false
while st == false do
o = menu(20, 8, menu1)
if o == 1 then
term.clear()
term.setCursorPos(1,1)
if enclvl > 0 then
print("Page Encrypted...")
print("Press Any key to go back to the menu...")
os.pullEvent("key")
else
print("Password Required...")
write("Password : ")
pw = read()
if pw == pass then
print("Correct!")
sleep(0.5)
print("This computer is Protected by a Pattern System.")
sleep(1)
pattern()
else
print("Incorrect!")
print("Press any key to go back to the menu...")
os.pullEvent("key")
end
end
elseif o == 2 then
diskCheck("left")
else
st = true
end
end
term.clear()
term.setCursorPos(1,1)
print("Shutting Down ...")
sleep(1)
os.shutdown()