codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
--[[ secboard Copyright (C) 2017 IGuess933, hdf73b@protonmail.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. --]] local loadOnce = 0 local cryptMode = -1 local strClip = "" -- prior-to-use is defined as: after you download this script and before you use the script -- therefore, preferably change these to new strings prior-to-use -- also pick a different saltSeed and saltExOffset -- use only letters for these two local strPass = "qitAFLWTunoElaNRWkVhZdMEcyAdBS" local strSeed = "SySkqAXLIGXacBuysnJLDPmPeV4NZk" -- only numbers for these two local saltSeed = 54 local saltExOffset = 3872 -- for preservation of past data: -- you must copy over the mod storage to any new.. -- ..installation of your OS to the appropriate folder. -- you must also copy this script as it is local mod_storage = minetest.get_mod_storage() local function conf_board() cryptMode = -1 local formspec = "size[10,10]" .. "bgcolor[#080808BB;true]" .. "background[0,0;10,10;gui_formbg.png;true]" .. "textarea[1,1;9,9;text;Password Text;" .. strPass .. "]" .. "button_exit[5,8;3,3;save;Save]" minetest.show_formspec("confsec", formspec) end local function show_board() if cryptMode == -1 then cryptMode = 0 end local formspec = "size[10,10]" .. "bgcolor[#080808BB;true]" .. "background[0,0;10,10;gui_formbg.png;true]" .. "textarea[1,1;9,9;text;Secret Text;" .. strClip .. "]" .. "button_exit[5,8;3,3;save;Save]" minetest.show_formspec("secboard", formspec) end minetest.register_chatcommand("confsec", { func = function(name, param) conf_board() end }) minetest.register_chatcommand("secboard", { func = function(name, param) show_board() end }) -- https://gist.github.com/obikag/7590516 function xor(a,b) local r = 0 local f = math.floor for i = 0, 31 do local x = a / 2 + b / 2 if x ~= f(x) then r = r + 2^i end a = f(a / 2) b = f(b / 2) end return r end function toBits(num) local t={} while num>0 do rest=math.fmod(num,2) t[#t+1]=rest num=(num-rest)/2 end --[[ t gives the binary number in reverse. To fix this the bits table will give the correct value by reversing the values in t. The result will be left paddied with zeros to eight digits ]] local bits = {} local lpad = 8 - #t if lpad > 0 then for c = 1,lpad do table.insert(bits,0) end end -- Reverse the values in t for i = #t,1,-1 do table.insert(bits,t[i]) end return table.concat(bits) end --Changes eight digit binary to decimal function toDec(bits) local bmap = {128,64,32,16,8,4,2,1} --binary map local bitt = {} for c in bits:gmatch(".") do table.insert(bitt,c) end local result = 0 for i = 1,#bitt do if bitt[i] == "1" then result = result + bmap[i] end end return result end function xorChars(chX,chY) local bitsA = toBits(string.byte(chX)) local bitsB = toBits(string.byte(chY)) local bitt = {} local bitu = {} for c in bitsA:gmatch(".") do table.insert(bitt,c) end for c in bitsB:gmatch(".") do table.insert(bitu,c) end local result = {} for i = 1,8,1 do table.insert(result,xor(bitu[i],bitt[i])) end return string.char(toDec(table.concat(result))) end function shuffleStr(strToShuffle, strSeed) local strA = tostring("") local strB = tostring("") local seedBlock = {} for ch in strSeed:gmatch(".") do local c = toBits(string.byte(ch)) table.insert(seedBlock,c) end local nStrToShuffle = string.len(strToShuffle) local nCounter = 1 local strSaltSeed = tostring(saltSeed) local nStrSaltSeedLen = string.len(strSaltSeed) local nCounterB = 1 for i = 1,#seedBlock do local bit = seedBlock[i] local cSalt = string.sub(strSaltSeed, nCounterB, nCounterB+1) local cShuff = string.sub(strToShuffle, nCounter, nCounter+1) if bit <= "z" and cSalt > "5" then strA = strA .. cShuff elseif bit <= "z" and cSalt < "5" then strB = strB .. cShuff elseif bit <= "Z" and cSalt < "5" then strA = strA .. cShuff elseif bit <= "Z" and cSalt > "5" then strB = strB .. cShuff elseif bit <= "z" and cSalt == "5" then strA = strA .. cShuff elseif bit <= "Z" and cSalt == "5" then strB = strB .. cShuff end nCounter = nCounter + 1 nCounterB = nCounterB + 1 if nCounter > nStrToShuffle then nCounter = 1 nCounterB = 1 break end if nCounterB > nStrSaltSeedLen then nCounterB = 1 end if nCounter > nStrToShuffle then break end end local result = tostring("") result = result .. strA result = result .. strB return result end --Encryption and Decryption Algorithm for XOR Block cipher function E(str) local saltSeedBackup = saltSeed local seedToUse = tostring("") seedToUse = seedToUse .. strSeed local keyToUse = tostring("") keyToUse = keyToUse .. strPass local passBlock = {} for ch in keyToUse:gmatch(".") do local c = ch table.insert(passBlock,c) end local strSaltSeed = tostring("") --split string into a table containing only binary numbers of each character local block = {} if cryptMode == 1 then str = minetest.compress(str, "deflate", "5") strSaltSeed = tostring(saltSeed) for ch in strSaltSeed:gmatch(".") do local c = ch table.insert(block,c) end elseif cryptMode == 2 then for ch in str:gmatch(".") do if ch >= "0" and ch <= "9" then strSaltSeed = strSaltSeed .. ch else break end end saltSeed = tonumber(strSaltSeed) end for ch in str:gmatch(".") do local c = ch table.insert(block,c) end --for each binary number perform xor transformation local nPassBlock = string.len(keyToUse) local nPassBlockCounter = 1 local nSeedRegenCounter = 1 local nBlockStart = 1 nBlockStart = string.len(strSaltSeed)+1 local blockFinal = {} for i = nBlockStart,#block do local chNew = xorChars(passBlock[nPassBlockCounter],block[i]) nPassBlockCounter = nPassBlockCounter + 1 if nPassBlockCounter > nPassBlock then nSeedRegenCounter = nSeedRegenCounter + 1 nPassBlockCounter = 1 keyToUse = shuffleStr(keyToUse,seedToUse) if nSeedRegenCounter > 15 then seedToUse = shuffleStr(seedToUse,keyToUse) nSeedRegenCounter = 1 end passBlock = {} for ch in keyToUse:gmatch(".") do local c = ch table.insert(passBlock,c) end end block[i] = chNew if cryptMode == 2 then table.insert(blockFinal, block[i]) end end saltSeed = saltSeedBackup local strToReturn = tostring("") if cryptMode == 1 then strToReturn = table.concat(block) return strToReturn elseif cryptMode == 2 then strToReturn = table.concat(blockFinal) strToReturn = minetest.decompress(strToReturn, "deflate", "5") return strToReturn end return table.concat(blockFinal) end function scrambleStr(str) local r = tostring("") r = E(str) return r end function descrambleStr(str) local r = tostring("") r = E(str) return r end -- Show form when the /formspec command is used. minetest.register_chatcommand("encGo", { func = function(name, param) if loadOnce == 0 then loadOnce = 1 saltSeed = tonumber(mod_storage:get_string("salt")) saltSeed = saltSeed + 3 end saltSeed = saltSeed + saltExOffset if cryptMode == -1 then return end cryptMode = 1 strClip = scrambleStr(strClip) strClip = minetest.encode_base64(strClip) mod_storage:set_string("salt", tostring(saltSeed)) end }) -- Show form when the /formspec command is used. minetest.register_chatcommand("decGo", { func = function(name, param) if loadOnce == 0 then loadOnce = 1 saltSeed = tonumber(mod_storage:get_string("salt")) saltSeed = saltSeed + 3 end if cryptMode == -1 then return end cryptMode = 2 strClip = minetest.decode_base64(strClip) saltSeed = tonumber(mod_storage:get_string("salt")) strClip = descrambleStr(strClip) end }) minetest.register_on_formspec_input(function(formname, fields) if formname == "confsec" then mod_storage:set_string("salt", tostring(saltSeed)) if fields.text == nil or not fields.save then return true else strPass = fields.text fields.text = "." return true end end if formname ~= "secboard" then return false else if fields.text == nil or not fields.save then return true end strClip = fields.text fields.text = "." return true end return true end)
Private
[
?
]
Run code
Submit