Advertisement
teru

Untitled

May 6th, 2014
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --I wrote a random character inserter in 2010.
  2. --This script takes a message, and given a known insertion, will recover
  3. --the original characters entered. This, importantly, does not recover the
  4. --original character order, so the resulting message will have typos unless
  5. --the original message and the original insertion contain no shared characters.
  6.  
  7. local insertion = "John Robert Partyka"
  8. local message = [[aooPtrl Jea ahsRnyborkt siookRtbaJrnrn tace yehP IaoPReJonhyttrba rk  caPbntRhrnr okyt aJaoe moani tberaJxP yrkhtRo ikPyatRnrn Jaot rhebo whabteJoPRervtaeark n ohrty IRtetrybP hnakoJo ar wrotakroantenybahJt R ,P ibhoPRo eyJratkta rn cbatrnye oaratnJoPh Rk mnRarPJtokektor yahbe a mhe yassroekag JrtaobeRntPs wJaytrRohoek rerbtnePah  itr tnk yatReobJParho mnitxr aetse yJRaokPhobr ttroRkn b rJhaetoheyaP wot rrnaP abdsoRtyeroJhk " JJaRroP earotybhotkhnn RJnorhrbtayoPeoekRtbra t  Patoaoehr  tktykabRarnr"PJy itbnyatPrRkJn oetar ooh eRae tarohtnrac hbykoJP wokrtroPohntrd.beaayRJ]]
  9. local outputMessage = ""
  10.  
  11. local extraSpaces = 0
  12. for _ in string.gmatch(insertion," ") do
  13.     extraSpaces = extraSpaces + 1
  14. end
  15.  
  16. local spacesToGo = 1 + extraSpaces
  17. local chr
  18. local lastWordLocation = 0
  19. local words = {}
  20. for idx=1,#message do
  21.     chr = string.sub(message,idx,idx)
  22.     if chr == " " or idx==#message then
  23.         spacesToGo = spacesToGo -1
  24.         if spacesToGo == 0 or idx==#message then
  25.             local startOfWord = lastWordLocation + 1
  26.             local endOfWord = idx - 1
  27.             lastWordLocation = idx
  28.             local word = string.sub(message,startOfWord, endOfWord)
  29.             table.insert(words,word,#words)
  30.             for iIdx=1, #insertion do
  31.                 word = string.gsub(word,string.sub(insertion,iIdx,iIdx),"",1)
  32.             end
  33.             outputMessage = outputMessage .. word .. " "
  34.             spacesToGo=1+extraSpaces
  35.         end
  36.     end
  37. end
  38. print "The constituent words..."
  39. local fmt = "%d. %s"
  40. for k,v in ipairs(words) do
  41. print(fmt:format(k,v))
  42. end
  43. print "And the final message..."
  44. print(outputMessage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement