Advertisement
xXm0dzXx

Test Encrypter

Oct 23rd, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. tArgs = { ... }
  2.  
  3. function printUsage()
  4. print("Usage: " ..shell.getRunningProgram().. " <encrypt/decrypt> [filename] [password]")
  5. end
  6.  
  7. if #tArgs < 1 then
  8. printUsage()
  9. return
  10. end
  11.  
  12. function encrypt( str, password )
  13. local mainString = ""
  14.  
  15. local passwordLocation = 1
  16. for i=1,#str do
  17. local str1 = string.byte( string.sub(str, i, i) ) + string.byte( string.sub(password, passwordLocation, passwordLocation) )
  18.  
  19. if passwordLocation == #password then
  20. passwordLocation = 1
  21. else
  22. passwordLocation = passwordLocation +1
  23. end
  24.  
  25. if i == 1 then
  26. mainString = str1
  27. else
  28. mainString = mainString .. "/" ..str1
  29. end
  30. end
  31.  
  32. return mainString
  33. end
  34.  
  35. function decrypt( str, password )
  36. tWords = {}
  37. for match in string.gmatch(str, "[^/\t]+") do
  38. table.insert( tWords, match )
  39. end
  40.  
  41. local dahString = ""
  42. local passwordLocation = 1
  43. for i=1,#tWords do
  44. local anodahwunbitezdahdust = tonumber(tWords[i]) - string.byte( string.sub(password, passwordLocation, passwordLocation) )
  45.  
  46. dahString = dahString .. string.char( anodahwunbitezdahdust )
  47.  
  48. passwordLocation = passwordLocation +1
  49. if passwordLocation == #password then
  50. passwordLocation = 1
  51. end
  52. end
  53.  
  54. return dahString
  55. end
  56.  
  57. if string.lower(tArgs[1]) == "encrypt" and fs.exists(tArgs[2]) and tArgs[3] then
  58. file = fs.open(tArgs[2], "r")
  59. local endResult = {}
  60. local characters = 0
  61. line = file.readLine()
  62. while line do
  63. characters = characters + #line
  64. table.insert(endResult, encrypt(line, tArgs[3]))
  65. line = file.readLine()
  66. end
  67.  
  68. local resultName = characters + math.random(1,10)
  69. results = fs.open("result_" ..resultName, "w")
  70. for i=1,#endResult do
  71. results.write(endResult[i])
  72. end
  73.  
  74. results.close()
  75. print("Encrypted " ..characters.. " characters. ")
  76. print("Password: " ..tArgs[3])
  77. print("Result file: result_" ..resultName)
  78.  
  79. elseif string.lower(tArgs[1]) == "decrypt" and fs.exists(tArgs[2]) and tArgs[3] then
  80.  
  81.  
  82. local resultNum = math.random(1,999)
  83. file = fs.open("result_" ..resultNum, "w")
  84. fileRead = fs.open( tArgs[2], "r")
  85. line = fileRead.readLine()
  86. local endResult = decrypt( line, tArgs[3] );
  87. file.write(endResult)
  88. fileRead.close()
  89. file.close()
  90.  
  91. print("Decrypted. Saved as: ")
  92. print("result_" ..resultNum)
  93. else
  94. printUsage()
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement