Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --I wrote a random character inserter in 2010.
- --This script takes a message, and given a known insertion, will recover
- --the original characters entered. This, importantly, does not recover the
- --original character order, so the resulting message will have typos unless
- --the original message and the original insertion contain no shared characters.
- local insertion = "John Robert Partyka"
- 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]]
- local outputMessage = ""
- local extraSpaces = 0
- for _ in string.gmatch(insertion," ") do
- extraSpaces = extraSpaces + 1
- end
- local spacesToGo = 1 + extraSpaces
- local chr
- local lastWordLocation = 0
- local words = {}
- for idx=1,#message do
- chr = string.sub(message,idx,idx)
- if chr == " " or idx==#message then
- spacesToGo = spacesToGo -1
- if spacesToGo == 0 or idx==#message then
- local startOfWord = lastWordLocation + 1
- local endOfWord = idx - 1
- lastWordLocation = idx
- local word = string.sub(message,startOfWord, endOfWord)
- table.insert(words,word,#words)
- for iIdx=1, #insertion do
- word = string.gsub(word,string.sub(insertion,iIdx,iIdx),"",1)
- end
- outputMessage = outputMessage .. word .. " "
- spacesToGo=1+extraSpaces
- end
- end
- end
- print "The constituent words..."
- local fmt = "%d. %s"
- for k,v in ipairs(words) do
- print(fmt:format(k,v))
- end
- print "And the final message..."
- print(outputMessage)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement