SHARE
TWEET

Obfuscate

a guest Aug 3rd, 2014 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // From: Kem Tekinay
  2. // forum.xojo.com/12423-obfuscation/p3#p92864
  3.  
  4. Function RndInRange (startIndex As Integer, endIndex As Integer) As Integer
  5. dim d as Double = Rnd
  6. dim range as Integer = endIndex - startIndex
  7. return Round( range * d ) + startIndex
  8. End Function
  9.  
  10. dim origString as String = SelText
  11. if origString.Trim = "" then
  12. print "Select some text first."
  13. return
  14. end if
  15.  
  16. dim chars() as String = Split( origString, "" )
  17.  
  18. dim startQuote as boolean = chars( 0 ) = """"
  19. dim endQuote as boolean = chars( chars.Ubound ) = """"
  20.  
  21. if endQuote then
  22. chars.Remove chars.Ubound
  23. end if
  24.  
  25. if chars.Ubound <> -1 and startQuote then
  26. chars.Remove 0
  27. end if
  28.  
  29. if chars.Ubound = -1 then
  30. print "Select some valid text first."
  31. return
  32. end if
  33.  
  34. dim stringToEncode as String = Join( chars, "" )
  35. //dim b as String = ShowDialog( "You are about to encode this string. Proceed?", stringToEncode, "Yes", "No", "" )
  36. //if b = "No" then
  37. //return
  38. //end if
  39.  
  40. dim index as Integer
  41. dim codeArr() as String
  42. dim indexArr() as String
  43. dim addArr() as String
  44. dim randomizerArr() as Integer
  45. for index = 0 to chars.Ubound
  46. dim thisAdd as Integer = RndInRange( 64001, 100000 )
  47. codeArr.Append Str( Asc( chars( index ) ) + thisAdd )
  48. indexArr.Append Str( index )
  49. addArr.Append Str( thisAdd )
  50. randomizerArr.Append RndInRange( 0, chars.Ubound * 100 )
  51. next index
  52.  
  53. randomizerArr.SortWith( codeArr, indexArr, addArr )
  54.  
  55. // Construct the code
  56. dim eol as String = EndOfLine
  57. dim resultArr() as String
  58.  
  59. resultArr.Append "// Encoding for value: "
  60. resultArr.Append stringToEncode
  61. resultArr.Append eol
  62.  
  63. resultArr.Append "dim codeArr() as Integer = Array( "
  64. resultArr.Append Join( codeArr, ", " )
  65. resultArr.Append " )"
  66. resultArr.Append eol
  67.  
  68. resultArr.Append "dim adderArr() as Integer = Array( "
  69. resultArr.Append Join( addArr, ", " )
  70. resultArr.Append " )"
  71. resultArr.Append eol
  72.  
  73. resultArr.Append "dim indexArr() as Integer = Array( "
  74. resultArr.Append Join( indexArr, ", " )
  75. resultArr.Append " )"
  76. resultArr.Append eol
  77.  
  78. resultArr.Append "indexArr.SortWith codeArr, adderArr"
  79. resultArr.Append eol
  80.  
  81. resultArr.Append eol
  82.  
  83. resultArr.Append "dim decodedChars() as String"
  84. resultArr.Append eol
  85.  
  86. resultArr.Append "for i as Integer = 0 to codeArr.Ubound"
  87. resultArr.Append eol
  88.  
  89. resultArr.Append "decodedChars.Append Chr( codeArr( i ) - adderArr( i ) )"
  90. resultArr.Append eol
  91.  
  92. resultArr.Append "next i"
  93. resultArr.Append eol
  94.  
  95. resultArr.Append eol
  96.  
  97. resultArr.Append "dim decodedString as String = Join( decodedChars, """" )"
  98. resultArr.Append eol
  99.  
  100. dim result as String = Join( resultArr, "" )
  101.  
  102. SelText = result
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top