Advertisement
Guest User

simple

a guest
Sep 21st, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. function format(text)
  2.   text = string.upper(text)
  3.   local bytevals = {}
  4.   for totab=1,#text,1 do
  5.     bytevals[totab] = string.byte(text,totab,totab)
  6.   end
  7.   return bytevals
  8. end
  9.  
  10. function unformat(text)
  11.   local myString = "-"
  12.   for tostr=1,#text,1 do
  13.     myString = myString .. string.char(text[tostr])
  14.   end
  15.   return myString
  16. end
  17.  
  18. function round1(text)
  19.   for bshift=2,#text,1 do
  20.     text[bshift] = bit.blshift(text[bshift],2)
  21.   end
  22.   return text
  23. end
  24.  
  25. function deround1(text)
  26.   for bshift=2,#text,1 do
  27.     text[bshift] = bit.brshift(text[bshift],2)
  28.   end
  29.   return text
  30. end
  31.  
  32. function round2(text,cyphert)
  33.   myEnc = cyphert
  34.   if #cyphert < #text then
  35.     encLen = #cyphert
  36.     divisor = math.ceil(#text/encLen)
  37.     for me=1,divisor,1 do
  38.       for space = 1,encLen,1 do
  39.         getLoc = me % encLen
  40.         myEnc[space + me*4] = myEnc[space]
  41.       end
  42.     end
  43.   end
  44.   for xorin=1,#text,1 do
  45.     text[xorin] = bit.bxor(text[xorin],myEnc[xorin])
  46.   end
  47.   return text
  48. end
  49. ------CYPHER-TEXT--------
  50. encText = {12,200,2,21}
  51.  
  52. -----ENCRYPT-------------
  53. c1 = format("Longr")
  54. c2 = round1(c1)
  55. c3 = round2(c2,encText)
  56. print("ENCRYPTED: ",table.concat(c3,","))
  57.  
  58. ----DECRYPT--------------
  59. c4 = round2(c3,encText)
  60. c5 = deround1(c4)
  61. c6 = unformat(c5)
  62. print("DECRYPTED: ",c6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement