Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tArgs = {...}
- --Enigma Security Software v3
- --Now with more Rotors And new Menus
- --Made By Wojbie
- --http://pastebin.com/NKhvzq2B
- --For Help: "Enigma help" or "Enigma ?" Atributes
- --For Advanced Use: "Enigma help2" or "Enigma ?2" Atributes
- --Rotors and Alphabeth Setup
- local function Rev(A) local Revt,i,j={} for i,j in ipairs(A) do Revt[j]=i end return Revt end
- local Rot = {
- {95,96,63,85,3,89,19,62,23,30,11,29,75,83,67,25,36,41,91,14,9,61,54,44,94,33,26,69,18,8,15,76,43,5,16,66,72,92,52,46,45,24,39,68,12,55,80,77,2,17,78,81,6,60,32,59,10,65,4,34,42,50,70,64,93,47,21,57,37,49,13,28,48,35,27,56,88,31,58,1,40,71,82,22,74,20,86,38,84,79,90,87,53,7,73,51},
- {95,96,66,2,49,67,43,20,61,76,51,50,35,82,13,17,1,91,3,85,16,27,63,23,33,87,39,81,30,59,42,70,78,9,72,7,37,54,89,44,36,31,57,64,41,45,83,21,38,65,25,90,48,18,40,6,74,22,62,46,88,77,32,34,12,84,68,29,69,75,73,4,24,94,56,15,19,79,58,53,92,55,14,26,47,80,52,10,60,71,5,86,28,93,11,8},
- {95,96,51,69,50,34,28,17,43,42,1,75,4,25,85,32,87,58,63,73,19,36,16,64,47,26,71,76,78,3,93,13,61,46,70,49,68,45,39,81,40,62,7,88,5,38,92,48,12,83,82,24,18,9,8,90,55,29,44,35,14,6,52,72,10,60,21,79,11,80,27,91,31,30,33,53,66,89,77,22,57,41,2,15,94,20,86,56,23,37,59,65,67,84,74,54},
- {76,30,55,90,91,83,22,48,74,64,77,40,71,57,92,51,66,85,56,41,1,17,18,93,36,27,16,43,50,75,21,70,38,31,84,58,82,45,53,52,78,96,12,34,3,11,68,6,46,9,94,67,61,44,37,47,35,63,69,4,25,81,2,65,32,62,7,29,33,14,28,19,72,24,60,54,39,95,23,73,79,20,59,87,10,88,13,86,42,5,49,26,8,89,80,15},
- {13,89,7,80,58,3,1,65,92,81,30,8,96,48,43,47,79,61,51,4,88,29,78,27,94,22,16,45,74,72,70,95,36,59,39,60,75,12,64,77,10,49,26,17,11,46,9,6,76,85,19,2,66,5,73,62,41,87,54,71,28,21,14,15,23,44,69,82,24,20,90,42,57,33,50,34,93,31,83,84,18,37,53,91,56,38,63,40,52,86,25,68,32,35,67,55},
- {70,10,14,8,48,88,63,12,37,91,71,20,50,65,87,78,79,46,39,75,29,9,53,36,13,21,24,19,44,81,49,58,22,61,42,96,66,64,56,27,86,47,89,84,59,74,32,30,16,6,72,33,95,57,80,69,34,5,85,94,41,90,60,2,23,67,35,76,77,52,68,11,7,51,73,26,62,25,15,17,45,43,82,1,92,83,18,93,28,3,55,4,40,38,31,54},
- {9,60,38,64,85,91,63,1,53,81,18,94,35,55,16,57,19,27,47,71,11,17,50,84,31,6,34,88,25,43,46,33,21,5,89,48,37,2,75,87,59,52,76,70,69,23,45,80,40,56,14,73,62,32,30,92,82,78,61,72,44,54,12,68,29,7,65,24,96,8,74,79,95,26,20,4,41,51,90,42,22,39,3,36,67,15,58,49,10,13,28,66,93,86,77,83},
- {82,16,57,49,4,20,61,93,47,90,28,3,35,81,84,24,69,94,19,32,21,79,33,68,38,64,76,26,72,31,30,13,39,70,92,18,5,10,25,11,14,71,46,45,78,41,88,15,53,56,51,74,89,8,83,9,86,87,50,2,73,95,34,40,29,43,60,12,96,58,42,23,52,6,1,55,36,7,17,66,77,67,80,59,63,44,37,85,48,75,62,22,91,65,54,27},
- {79,64,53,47,28,39,63,43,26,9,5,19,69,29,12,84,11,15,18,46,60,56,27,33,24,17,74,85,34,95,51,88,72,13,16,4,77,49,59,71,25,22,70,30,14,42,8,52,92,41,87,55,83,6,67,57,38,61,54,35,81,45,1,23,48,3,80,90,96,75,32,76,36,37,86,89,78,40,62,58,66,10,73,7,44,65,82,94,50,91,20,21,93,2,68,31},
- {24,88,80,16,37,30,6,19,7,22,3,75,81,90,46,18,21,1,4,9,59,72,23,91,11,86,54,49,69,50,66,5,51,41,71,74,17,38,20,67,96,84,85,14,76,53,36,70,89,47,94,2,13,25,39,78,92,42,28,95,31,82,56,26,87,65,44,55,34,45,35,68,33,77,8,32,57,40,93,79,61,64,62,52,63,83,73,27,12,60,15,58,48,10,43,29},
- }
- Rots={}
- local toR = {Rev(Rot[1]),Rev(Rot[2]),Rev(Rot[3]),Rev(Rot[4]),Rev(Rot[5]),Rev(Rot[6]),Rev(Rot[7]),Rev(Rot[8]),Rev(Rot[9]),Rev(Rot[10])}
- local Rset ={}
- local Al = {" ","!","\"","#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~","\000",}
- local lA = Rev(Al)
- local Alen = #Al
- --Color Buttons Setup
- local button = {}
- local Tittle = {}
- local off
- -- Selecting Buttons and Colors Depending on computer/turtle normal/advanced
- if turtle then
- if term.isColor() then
- local g,w,r,y,b=colors.lime,colors.white,colors.red,colors.yellow,colors.black
- button = {
- {20,03,3,3,"1",g,w},{24,03,3,3,"2",g,w},{28,03,3,3,"3",g,w},{32,03,3,3,"4",g,w},{36,03,3,3,"5",g,w},
- {20,07,3,3,"6",g,w},{24,07,3,3,"7",g,w},{28,07,3,3,"8",g,w},{32,07,3,3,"9",g,w},{36,07,3,3,"0",g,w},
- {02,11,11,1,"Enter",g,w},
- {15,11,11,1,"Reset - r",y,r},
- {28,11,11,1,"Exit - q",r,g},
- {1,13,18,1,"Basic Mode - Tab",w,b},
- {23,13,17,1,"Hide/show * - h",w,b},
- } -- end button
- Tittle = {6,1,29,1,"Enigma Security Software v2",w,r}
- off=2
- else
- local w,b=colors.white,colors.black
- button = {
- {21,05,17,1,"Next - Enter",w,b},
- {21,07,17,1,"Reset - r",w,b},
- {21,09,17,1,"Exit - q",w,b},
- {1,13,18,1,"Basic Mode - Tab",w,b},
- {23,13,17,1,"Hide/show * - h",w,b},
- } -- end button
- Tittle = {6,1,29,1,"Enigma Security Software v2",w,b}
- off=3
- end
- else
- if term.isColor() then
- local g,w,r,y,b=colors.lime,colors.white,colors.red,colors.yellow,colors.black
- button = {
- {21,04,3,3,"1",g,w},{25,04,3,3,"2",g,w},{29,04,3,3,"3",g,w},
- {21,08,3,3,"4",g,w},{25,08,3,3,"5",g,w},{29,08,3,3,"6",g,w},
- {21,12,3,3,"7",g,w},{25,12,3,3,"8",g,w},{29,12,3,3,"9",g,w},
- {25,16,3,3,"0",g,w},
- {37,05,11,3,"Enter",g,w},
- {37,09,11,3,"Reset - r",y,r},
- {37,13,11,3,"Exit - q",r,g},
- {1,19,18,1,"Basic Mode - Tab",w,b},
- {35,19,17,1,"Hide/show * - h",w,b},
- } -- end button
- Tittle = {12,1,29,1,"Enigma Security Software v2",w,r}
- off=5
- else
- local w,b=colors.white,colors.black
- button = {
- {26,05,19,3,"Next - Enter",w,b},
- {26,09,19,3,"Reset - r",w,b},
- {26,13,19,3,"Exit - q",w,b},
- {1,19,18,1,"Basic Mode - Tab",w,b},
- {35,19,17,1,"Hide/show * - h",w,b},
- } -- end button
- Tittle = {12,1,29,1,"Enigma Security Software v2",w,b}
- off=6
- end
- end
- local function bmake(A)
- local i,j
- term.setBackgroundColor(A[6])
- term.setTextColor(A[7])
- for i=1,A[4] do
- term.setCursorPos(A[1],A[2]+i-1)
- for j=1,A[3] do write(" ") end
- end
- term.setCursorPos(A[1]+A[3]/2-#A[5]/2,A[2]+A[4]/2)
- write(A[5])
- end
- -- File Usage
- local function save(A,B)
- local file = fs.open(tostring(A),"w")
- file.write(B)
- file.close()
- end
- local function saveT(A,B) save(A,textutils.serialize(B)) end
- local function get(A)
- local file = fs.open(tostring(A),"r")
- if not file then return false end
- local data = file.readAll()
- file.close()
- if data then return data end
- end
- local function getT(A)
- local data = get(A)
- if data then data = textutils.unserialize(data) end
- if data then return data end
- end
- --basic functions
- local function norm(A)
- while A>94 do A=A-Alen end
- while A<1 do A=A+Alen end
- return A
- end
- local function tick()
- Rset[1]=Rset[1]+1
- if Rset[1]>=Alen then Rset[1]=0 Rset[2]=Rset[2]+1 end
- if Rset[2]>=Alen then Rset[2]=0 Rset[3]=Rset[3]+1 end
- if Rset[3]>=Alen then Rset[3]=0 end
- end
- local function encrypt(A)
- local B
- B = Rot[Rots[1]][norm(A+Rset[1])]
- B = Rot[Rots[2]][norm(B+Rset[2])]
- B = Rot[Rots[3]][norm(B+Rset[3])]
- B = norm(B-(Alen/2))
- B = norm(toR[Rots[3]][B]-Rset[3])
- B = norm(toR[Rots[2]][B]-Rset[2])
- B = norm(toR[Rots[1]][B]-Rset[1])
- tick()
- return B
- end
- local function codestring(A)
- local B={}
- local C
- for i=1,string.len(A) do
- C=string.sub(A,i,i)
- if lA[C] then B[i]=Al[encrypt(lA[C])] else B[i]=C end
- end
- B=table.concat(B)
- return B
- end
- -- Basic Pass Screen
- local function Bwreact()
- term.clear()
- term.setCursorPos(1,1)
- print("Select Rotors 0-9")
- while not Rots[1] or Rots[1]<0 or Rots[1]>9 do print("Rotor 1:") Rots[1]=tonumber(read("*")) end
- while not Rots[2] or Rots[2]<0 or Rots[2]>9 do print("Rotor 2:") Rots[2]=tonumber(read("*")) end
- while not Rots[3] or Rots[3]<0 or Rots[3]>9 do print("Rotor 3:") Rots[3]=tonumber(read("*")) end
- Rots[1],Rots[2],Rots[3]=Rots[1]+1,Rots[2]+1,Rots[3]+1
- term.clear()
- term.setCursorPos(1,1)
- print("Enter Rotors Positons")
- while not Rset[1] or Rset[1]<0 or Rset[1]>99 do print("Rotor 1 Positons:") Rset[1]=tonumber(read("*")) end
- while not Rset[2] or Rset[2]<0 or Rset[2]>99 do print("Rotor 2 Positons:") Rset[2]=tonumber(read("*")) end
- while not Rset[3] or Rset[3]<0 or Rset[3]>99 do print("Rotor 3 Positons:") Rset[3]=tonumber(read("*")) end
- term.clear()
- term.setCursorPos(1,1)
- end
- --Advanced Pass Screen
- local function react()
- local ro,cur,lx,ly,hide=1,100,1,1,true
- local function btest(A,B)
- for i=1,#button do
- local i=button[i]
- if A>=i[1] and A<=i[1]+i[3]-1 and B>=i[2] and B<=i[2]+i[4]-1 then return i[5] end
- end
- return "nope"
- end
- local function numb(A,B,C)
- if hide then
- if A==ro then
- B=B-100
- if B == 0 then return ""
- elseif B < 10 then return "*"
- else return "**"
- end
- else return "**" end
- else
- if A==ro then
- B=B-100
- return tostring(B)
- else
- if C then
- if Rots[A] then return tostring(Rots[A]-1) else return "0" end
- else
- if Rset[A-3] then return tostring(Rset[A-3]) else return "00" end
- end
- end
- end
- end
- local function getro(A,B)
- if A<=3 then Rots[A]=B+1
- else Rset[A-3]=B end
- if not Rots[1] or Rots[1]<1 or Rots[1]>10 then return 1
- elseif not Rots[2] or Rots[2]<1 or Rots[2]>10 then return 2
- elseif not Rots[3] or Rots[3]<1 or Rots[3]>10 then return 3
- elseif not Rset[1] or Rset[1]<0 or Rset[1]>99 then return 4
- elseif not Rset[2] or Rset[2]<0 or Rset[2]>99 then return 5
- elseif not Rset[3] or Rset[3]<0 or Rset[3]>99 then return 6
- else return 7 end
- end
- local event,p1,p2,p3,p4,p5,a
- while true do
- term.setCursorPos(2,off)
- write("Select Rotors 0-9")
- term.setCursorPos(2,off+1)
- write("Rotor 1:"..numb(1,cur,true).." ") if ro==1 then lx,ly=term.getCursorPos() end
- term.setCursorPos(2,off+2)
- write("Rotor 2:"..numb(2,cur,true).." ") if ro==2 then lx,ly=term.getCursorPos() end
- term.setCursorPos(2,off+3)
- write("Rotor 3:"..numb(3,cur,true).." ") if ro==3 then lx,ly=term.getCursorPos() end
- term.setCursorPos(2,off+4)
- write("Startup Positions:")
- term.setCursorPos(2,off+5)
- write("Rotor 1 Pos:"..numb(4,cur,false).." ") if ro==4 then lx,ly=term.getCursorPos() end
- term.setCursorPos(2,off+6)
- write("Rotor 2 Pos:"..numb(5,cur,false).." ") if ro==5 then lx,ly=term.getCursorPos() end
- term.setCursorPos(2,off+7)
- write("Rotor 3 Pos:"..numb(6,cur,false).." ") if ro==6 then lx,ly=term.getCursorPos() end
- term.setCursorPos(lx-2,ly)
- term.setCursorBlink(true)
- event,p1,p2,p3,p4,p5 = os.pullEvent()
- if event=="mouse_click" then
- a = btest(p2,p3)
- if a=="nope" then --nothing to do here
- elseif a=="Hide/show * - h" then hide = not hide
- elseif a=="Enter" then ro=getro(ro,cur-100) cur=100
- if ro==7 and Rots[1] and Rots[2] and Rots[3] and Rset[1] and Rset[2] and Rset[3] then break
- elseif ro==7 then ro,cur=1,100 Rset={} Rots={} end
- elseif a=="Reset - r" then ro,cur=1,100 Rset={} Rots={}
- elseif a=="Exit - q" then Rset[4]=true break
- elseif a=="Basic Mode - Tab" then Bwreact() break
- else cur=cur*10+tonumber(a) while cur>199 do cur=cur-100 end end
- end
- if event=="char" then
- a = p1
- if type(tonumber(a))=="number" then cur=cur*10+tonumber(a) while cur>199 do cur=cur-100 end end
- end
- if event=="key" then
- a = p1
- if a==35 then hide = not hide
- elseif a==28 then ro=getro(ro,cur-100) cur=100
- if ro==7 and Rots[1] and Rots[2] and Rots[3] and Rset[1] and Rset[2] and Rset[3] then break
- elseif ro==7 then ro,cur=1,100 Rset={} Rots={} end
- elseif a==19 then ro,cur=1,100 Rset={} Rots={}
- elseif a==16 then Rset[4]=true break
- elseif a==15 then Bwreact() break end
- end
- end
- end
- -- Start of Program
- --Command line Rotors Reciving
- if tArgs[1]=="Rotors" then
- table.remove (tArgs , 1)
- Rots=textutils.unserialize(tArgs[1])
- Rots[1],Rots[2],Rots[3]=Rots[1]+1,Rots[2]+1,Rots[3]+1
- table.remove (tArgs , 1)
- Rset=textutils.unserialize(tArgs[1])
- table.remove (tArgs , 1)
- --Cheack if passable numbers
- if not Rots[1] or Rots[1]<1 or Rots[1]>10
- or not Rots[2] or Rots[2]<1 or Rots[2]>10
- or not Rots[3] or Rots[3]<1 or Rots[3]>10
- or not Rset[1] or Rset[1]<0 or Rset[1]>99
- or not Rset[2] or Rset[2]<0 or Rset[2]>99
- or not Rset[3] or Rset[3]<0 or Rset[3]>99
- then print("Wrong Setup") return end
- end
- -- test if selfencrypting
- if not coded then
- -- Help page
- if tArgs[2]=="help" or tArgs[2]=="?" or tArgs[1]=="help" or tArgs[1]=="?" then
- term.clear()
- term.setCursorPos(1,1)
- sleep(0.01) -- clear os.pullEvent() queque
- write(" Welcome in Enigma Security Software Help-page\
- List of Commands:\n\
- 1) enigma code [path] - Encrypt/Decrypt [path]\
- file into [path].code file.\n\
- 2) enigma codein [path] - Encrypt/Decrypt [path]\
- file into itself (overwrites content) file.\n\
- 3) enigma run [path] - Decrypt [path] file and\
- run it. Efects on non coded file are undefined.\n\
- 4) enigma exec [path] - Encrypt/Decrypt [path]\
- file into [path].code file and add self-\
- decrypting code. This file can be used without\
- main Enigma file. Simply run it and enter Pass.\n\
- Use enigma help2 or enigma ?2 for Advanced Usage")
- os.pullEvent("key")
- write("\n")
- return
- end
- -- Advanced Usage page
- if tArgs[2]=="help2" or tArgs[2]=="?2" or tArgs[1]=="help2" or tArgs[1]=="?2" then
- term.clear()
- term.setCursorPos(1,1)
- sleep(0.01) -- clear os.pullEvent() queque
- write(" Welcome in Enigma Security Software Help-page 2\
- Advanced Use:\n\
- If you need it you can change file made using\
- 4)-exec back into standard Enigma program by\
- removing 1st line in file (local coded = {\"code\"})\n\
- When using 4)-exec file all Atributes given to\
- Enigma will be passed on to decoded progam.\n\
- When using 3)-run option of Enigma all Atributes\
- after first 2 will be passed on to decoded progam.\
- That means 3th Atribute will become 1st ect \n\
- Special Thanks:\
- Lyqyd (Cc Forums) for help with assert()()\
- Dr James Grime on Numberphile - Enigma Video\
- My Cat for laying on my lap as I coded this")
- os.pullEvent("key")
- write("\n")
- return
- end
- --test if file is correct
- if not (tArgs[2] and tArgs[1]) or not(tArgs[1]=="code" or tArgs[1]=="codein" or tArgs[1]=="run" or tArgs[1]=="exec") then print("Wrong Command - use enigma help or enigma ? for help") return end
- if not fs.exists(tArgs[2]) then print("There is no file at "..tArgs[2]..". Use the absolute path to file - use enigma help or enigma ? for help") return end
- if fs.isDir(tArgs[2]) then print("Path "..tArgs[2].." refers to Directory - This version is not able to encrypt direcory - use enigma help or enigma ? for help") return end
- if fs.isReadOnly(tArgs[2]) and tArgs[1]=="codein" then print("Can't codein in read-only file - use enigma help or enigma ? for help") return end
- end
- -- call in Pass Screen
- while not Rots[1] and not Rots[2] and not Rots[3] and not Rset[1] and not Rset[2] and not Rset[3] do
- local i
- term.clear()
- bmake(Tittle)
- for i=1,#button do bmake(button[i]) end
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- react()
- term.clear()
- term.setCursorPos(1,1)
- term.setCursorBlink(false)
- if Rset[4] then return end
- end
- -- Run Coding/Decoding
- if coded then
- term.clear() term.setCursorPos(1,1) term.setCursorBlink(false)
- assert(loadstring(string.gsub(codestring(textutils.unserialize(coded[1])), "\000", "\n")),"Wrong Passcode")(unpack(tArgs))
- else
- if tArgs[1]=="code" then
- save(tArgs[2]..".code",codestring(get(tArgs[2])))
- elseif tArgs[1]=="codein" then
- save(tArgs[2],codestring(get(tArgs[2])))
- elseif tArgs[1]=="run" then
- local text = get(tArgs[2])
- table.remove (tArgs , 1)
- table.remove (tArgs , 1)
- term.clear() term.setCursorPos(1,1) term.setCursorBlink(false)
- assert(loadstring(string.gsub(codestring(text), "\000", "\n")),"Wrong Passcode")(unpack(tArgs))
- elseif tArgs[1]=="exec" then
- save(tArgs[2]..".code","local coded = "..textutils.serialize({codestring(string.gsub(get(tArgs[2]), "\n" , "\000" ))}).."\r\n"..get(shell.getRunningProgram()))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement