Wyvern67

Breaking starbounder.org's fucking nasty ass shitty captcha

Aug 28th, 2016
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.39 KB | None | 0 0
  1. --What is the first digit of the number five hundred seventy-five million three hundred seventy-eight thousand eight hundred sixty-one?
  2. --I DON'T KNOW !
  3. --This is easier to do for a computer than a human
  4. --This is the worst captcha i've ever seen
  5. --please, don't use that kind of captcha
  6.  
  7. units = {}
  8. units.one = 1
  9. units.two = 2
  10. units.three = 3
  11. units.four = 4
  12. units.five = 5
  13. units.six = 6
  14. units.seven = 7
  15. units.eight = 8
  16. units.nine = 9
  17.  
  18. deci = {}
  19. deci.twenty  = 2
  20. deci.thirty  = 3
  21. deci.forty   = 4
  22. deci.fifty   = 5
  23. deci.sixty   = 6
  24. deci.seventy = 7
  25. deci.eighty  = 8
  26. deci.ninety  = 9
  27.  
  28. special = {}
  29. special.ten       = {1, 0}
  30. special.eleven    = {1, 1}
  31. special.twelve    = {1, 2}
  32. special.thirteen  = {1, 3}
  33. special.fourteen  = {1, 4}
  34. special.fifteen   = {1, 5}
  35. special.sixteen   = {1, 6}
  36. special.seventeen = {1, 7}
  37. special.eighteen  = {1, 8}
  38. special.nineteen  = {1, 9}
  39.  
  40. function nullret()
  41.     return "_","_","_","_","_","_","_","_","_"
  42. end
  43.  
  44. function breakDown9d(tn)
  45.     --tn: text number
  46.     print(tn)
  47.  
  48.     --in case the whole captcha was inputted and not just the text number
  49.     if string.find(tn, "of the number") then
  50.         tn = string.match(tn, "of the number (.*)\?")
  51.     elseif string.match(tn, "^ ") then
  52.         tn = string.match(tn, "^ (.*)")
  53.     end
  54.     if string.find(tn, "\?") then
  55.         tn = string.match(tn, "(.*)\?")
  56.     end
  57.     --now tn looks like:
  58.     --five hundred seventy-five million three hundred seventy-eight thousand eight hundred sixty-one
  59.  
  60.     local a,b,c,d,e,f,g,h,i, rest
  61.     local millions,thousands,hundreds
  62.  
  63.     millions, rest = string.match(tn, "(.*) million (.*)")
  64.     if not rest then return nullret() end
  65.     thousands, rest = string.match(rest, "(.*) thousand (.*)")
  66.     hundreds = rest
  67.     --split "five hundred seventy-five million three hundred seventy-eight thousand eight hundred sixty-one"
  68.         --millions  = five hundred seventy-five
  69.         --thousands = three hundred seventy-eight
  70.         --hundreds  = eight hundred sixty-one
  71.  
  72.     a,b,c = breakDown3d(millions)
  73.     d,e,f = breakDown3d(thousands)
  74.     g,h,i = breakDown3d(hundreds)
  75.  
  76.     return a,b,c,d,e,f,g,h,i
  77. end
  78. function breakDown3d(tn)
  79.     --tn looks like something like
  80.     --"five hundred seventy-five"
  81.  
  82.     local a,b,c
  83.     --split "one hundred twenty-six" -> "one", "twenty-six"
  84.     --the ? is for the 9/100 chance of just getting "x hundred". Makes the space optional.
  85.     a, rest = string.match(tn, "(.*) hundred ?(.*)")
  86.     a = units[a] or "_"
  87.     --because units["one"] is 1
  88.     --if units[a] is undefined, or sets the value to "_"
  89.  
  90.     --if not rest then
  91.     --  --"one hundred"
  92.     --  a = 0
  93.     --  rest = tn
  94.     --end
  95.  
  96.     --parsing the last two digits. Lots of cases.
  97.     if string.find(rest, "-") then
  98.     --ex case: "one hundred [twenty-six]"
  99.         b, c = string.match(rest, "(.*)\-(.*)")
  100.         b = deci[b]
  101.         c = units[c]
  102.     elseif special[rest] then
  103.     --ex case: "one hundred [twelve,thirteen...]"
  104.         b, c = unpack(special[rest])
  105.     elseif units[rest] then
  106.     --ex case: "one hundred [four,five,six...]"
  107.         b = 0
  108.         c = units[rest]
  109.     elseif deci[rest] then
  110.     --ex case: "one hundred [twenty,thirty...]"
  111.         b = deci[rest]
  112.         c = 0
  113.     elseif rest == "" then
  114.     --ex case: "one hundred[]"
  115.         b = 0
  116.         c = 0
  117.     end
  118.    
  119.     return a or "_", b or "_", c or "_"
  120. end
  121.  
  122. --example of use
  123. local captcha = "What is the fifth digit of the number six hundred seventy-six million seven hundred eighty-two thousand five hundred seventeen? "
  124. local n = {breakDown9d(captcha)}
  125. print(table.concat(n, " "))
  126. print("1 2 3 4 5 6 7 8 9")
Add Comment
Please, Sign In to add comment