Alyssa

Simple Encoding

Oct 18th, 2014
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. --After I looked this up on December 27th 2014, I found out this is basically (exactly) a hex Vigenere Ciphet
  2. local nify = { "0", "1","2","3","4","5","6","7","8","9","a","b","c","d","e","f" }
  3.  
  4. local function code(key, msg, mode)
  5.  key = tostring(key)
  6.  msg = tostring(msg)
  7.  local kn = 1
  8.  local nmsg = ""
  9.  for i = 1, #msg do
  10.   cc = string.sub(msg, i, i)
  11.   for b = 1, 16 do
  12.    if cc == nify[b] then
  13.     ccn = b
  14.    end
  15.   end
  16.   for c = 1, 16 do
  17.    if string.sub(key, kn, kn) == nify[c] then
  18.     knn = c
  19.    end
  20.   end
  21.   if mode == "encode" then
  22.    ccn = ccn + knn
  23.   elseif mode == "decode" then
  24.    ccn = ccn - knn
  25.   end
  26.   if ccn >= 17 then
  27.    ccn = ccn - 16
  28.   end
  29.   if ccn <= 0 then
  30.    ccn = ccn + 16
  31.   end
  32.   --print(ccn)
  33.   nmsg = nmsg..nify[ccn]
  34.   if kn == #key then
  35.    kn = 1
  36.   else
  37.    kn = kn +1
  38.   end
  39.  end
  40.  return nmsg
  41. end
  42.  
  43. function decode(key, msg)
  44.  local tr = code(key, msg, "decode")
  45.  return tr
  46. end
  47.  
  48. function encode(key, msg)
  49.  local tr = code(key, msg, "encode")
  50.  return tr
  51. end
Advertisement
Add Comment
Please, Sign In to add comment