Advertisement
jakendrick3

Scytale Encryption

May 3rd, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. -- pronounced ski-tah-lee just fyi
  2.  
  3. function switchConvert(num)
  4.   if num >= 0 and num < 10 then
  5.     return num
  6.   elseif num == 9 then
  7.     return 'a'
  8.   elseif num == 10 then
  9.     return 'b'
  10.   elseif num == 11 then
  11.     return 'c'
  12.   elseif num == 12 then
  13.     return 'd'
  14.   elseif num == 13 then
  15.     return 'e'
  16.   elseif num == 14 then
  17.     return 'f'
  18.   elseif num == 15 then
  19.     return 'g'
  20.   elseif num == 16 then
  21.     return 'h'
  22.   elseif num == 17 then
  23.     return 'i'
  24.   elseif num == 18 then
  25.     return 'j'
  26.   elseif num == 19 then
  27.     return 'k'
  28.   elseif num == 20 then
  29.     return 'l'
  30.   elseif num == 21 then
  31.     return 'm'
  32.   elseif num == 22 then
  33.     return 'n'
  34.   elseif num == 23 then
  35.     return 'o'
  36.   elseif num == 24 then
  37.     return 'p'
  38.   elseif num == 25 then
  39.     return 'q'
  40.   elseif num == 26 then
  41.     return 'r'
  42.   elseif num == 27 then
  43.     return 's'
  44.   elseif num == 28 then
  45.     return 't'
  46.   elseif num == 29 then
  47.     return 'u'
  48.   elseif num == 30 then
  49.     return 'v'
  50.   elseif num == 31 then
  51.     return 'w'
  52.   elseif num == 32 then
  53.     return 'x'
  54.   elseif num == 33 then
  55.     return 'y'
  56.   elseif num == 34 then
  57.     return 'z'
  58.   else
  59.     return "-"
  60.   end
  61. end
  62.  
  63. function fill()
  64.   local initial = math.random(34)
  65.  
  66.   local parsedInitial = switchConvert(initial)
  67.  
  68.   return parsedInitial
  69. end
  70.  
  71. function wrap(parchment, sec)
  72.   local point = 1
  73.   local wrap = ""
  74.   local stick = ""
  75.   local parchLen = #parchment
  76.  
  77.   for point=1,parchLen do
  78.     local nextLen = math.random(sec)
  79.     stick = stick..nextLen
  80.    
  81.     for i=1, nextLen - 1 do
  82.       wrap = wrap..scytale.fill()
  83.     end
  84.    
  85.     wrap = wrap..string.sub(parchment, point, point)
  86.   end
  87.  
  88.   return wrap, stick
  89. end
  90.  
  91. function unwrap(parchment, stick)
  92.   local unwrap = ""
  93.   local wrappedLen = #parchment
  94.   local point = 0
  95.   local stickPoint = 1
  96.  
  97.   while true do
  98.     stickCurrent = string.sub(stick, stickPoint, stickPoint)
  99.    
  100.     if point == wrappedLen then
  101.       break
  102.     end
  103.    
  104.     point = point + stickCurrent
  105.     stickPoint = stickPoint + 1
  106.    
  107.     unwrap = unwrap..string.sub(parchment, point, point)
  108.   end
  109.  
  110.   return unwrap
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement