guitarplayer616

Passcode Cracker

Jul 28th, 2015
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.98 KB | None | 0 0
  1. --passcode breaker
  2. --between 4 - infintity characters
  3. --base 26 or 36 or 52 or 62
  4.  
  5. shell.run("clear")
  6.  
  7. local input = io.read()
  8. --local times = tonumber(input)
  9. local times = 1
  10. --local password = "pass"
  11. local password = input
  12. local alphabet = {'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',}
  13. local cells = {}
  14.  
  15.  
  16. --len = 5
  17. --26^(len-1)
  18.  
  19. function findLen(times)
  20.     local check = 1
  21.     while true do
  22.         if times <= 26 then
  23.             return check
  24.         elseif 26^(check-1) > times then
  25.             return check-1
  26.         else
  27.             check = check + 1
  28.         end
  29.     end
  30. end
  31.    
  32.  
  33. --[[
  34. 500,000
  35.  
  36. math.floor --> 500,000 / 26^(5-1) = 1 in 5
  37. 500,000 % 26^(5-1) = 43,024
  38.  
  39. math.floor --> 43,024 / 26^(4-1) = 2 in 4
  40. 43,024 % 26^(4-1) = 7,872
  41.  
  42. math.floor --> 7,872 / 26^(3-1) =
  43.  
  44. ]]
  45.  
  46. --[[
  47. 27
  48.  
  49. math.floor(27/26^(2-1)) = 1 in 2
  50. 27 % 26 = 1
  51.  
  52. math.floor(1/26^(1-1)) = 1 in 1
  53. 27 % 1 = 0
  54.  
  55. aabb
  56. ]]
  57.  
  58. function cycle2(len,times)
  59.     --len = 3
  60.     --times = 676
  61.    
  62.     local t = {}
  63.     local rem = times
  64.     dig = 0 --(len)
  65.     while rem ~= 0 do
  66.         t[len-dig] = math.floor(rem/26^(len-1-dig))
  67.         rem = rem % (26^(len-1-dig))
  68.         dig = dig + 1
  69.     end
  70.     return t
  71. end
  72.    
  73.  
  74.  
  75. function cycle(len)
  76.     --aaaa aaab aaac aaad aaae
  77.     local string = ""
  78.     for i = 1,len do
  79.         if i == 1 then
  80.             string = alphabet[times%26 + 1]..string
  81.         elseif i == 2 then
  82.             string = alphabet[math.floor(times/26^1) + 1]..string
  83.         elseif i == 3 then
  84.             string = alphabet[math.floor(times/26^2) + 1]..string
  85.         elseif i == 4 then
  86.             string = alphabet[math.floor(times/26^3) + 1]..string
  87.         end
  88.     end
  89.     times = times + 1
  90.     return(string)
  91. end
  92.  
  93. function convToString(table)
  94.     local string = ""
  95.     for i,v in ipairs(table) do
  96.         if v then
  97.             if v == 0 then
  98.                 string = string..alphabet[1]
  99.             else
  100.                 string = string..alphabet[v]
  101.             end
  102.         end
  103.     end
  104.     return string
  105. end
  106.  
  107. function convToNumber(string)
  108.     local string = string
  109.     local table = {}
  110.     for i = 1, string:len() do
  111.         for k,v in pairs(alphabet) do
  112.             if string:sub(i,i) == v then
  113.                 table[i] = k
  114.             end
  115.         end
  116.     end
  117.     return table
  118. end
  119.  
  120. function convToTrueNumber(table)
  121.     local num = 0
  122.     for i,v in ipairs(table) do
  123.         if v then
  124.             num = num + (v * (26^(i-1)))
  125.         end
  126.     end
  127.     return num
  128. end
  129.  
  130.  
  131. shell.run("clr")
  132. while true do
  133.     length = findLen(times)
  134.     --length = password:len() --definitely not cheating
  135.     table = cycle2(length,times)
  136.     try = convToString(table)
  137.     term.setCursorPos(1,1)
  138.     term.clearLine()
  139.     print(try)
  140.     if try == password then
  141.         return password, times
  142.     end
  143.     times = times + 1
  144.     sleep(.00001)
  145. end
  146.  
  147.  
  148. --[[
  149. local h = fs.open("log",'w')
  150. local length = findLen(tonumber(input))
  151. local table = cycle2(length)
  152. for i,v in ipairs(table) do
  153.     if v then
  154.         h.writeLine(i.." = "..v)
  155.     end
  156. end
  157. local convString = convToString(table)
  158. h.writeLine(nil)
  159. h.writeLine(convString)
  160. h.writeLine(nil)
  161. local convTab = convToNumber(convString)
  162. h.write(textutils.serialize(convTab))
  163. h.writeLine(nil)
  164. h.writeLine(convToTrueNumber(convTab))
  165. h.close()
  166. ]]
Add Comment
Please, Sign In to add comment