Created
December 4, 2016 22:02
-
-
Save LastTalon/a383fff6bb3d78ad4bc5be56930b322b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shuffle(message) | |
local shuffle = {} | |
for i=1, string.len(message) do | |
shuffle[i] = string.sub(message, i, i) | |
end | |
local k = 0 | |
local temp = nil | |
for n = #shuffle, 1, -1 do | |
k = math.random(1, n) | |
temp = shuffle[k] | |
shuffle[k] = shuffle[n] | |
shuffle[n] = temp | |
end | |
return table.concat(shuffle) | |
end | |
function rScramble(message) | |
local done = false | |
local scramble = "" | |
local pLoc = 1 | |
local sLoc = 1 | |
local eLoc = 1 | |
local word = nil | |
while not done do | |
sLoc, eLoc, word = string.find(message, "(%a+)", pLoc) | |
if word ~= nil then | |
if eLoc - sLoc < 1 then | |
scramble = scramble .. string.sub(message, pLoc, sLoc) | |
else | |
scramble = scramble .. string.sub(message, pLoc, sLoc) | |
.. shuffle(string.sub(message, sLoc + 1, eLoc - 1)) | |
.. string.sub(message, eLoc, eLoc) | |
end | |
pLoc = eLoc + 1 | |
else | |
done = true | |
end | |
end | |
scramble = scramble .. string.sub(message, pLoc) | |
return scramble | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment