Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // From: Kem Tekinay
- // forum.xojo.com/12423-obfuscation/p3#p92864
- Function RndInRange (startIndex As Integer, endIndex As Integer) As Integer
- dim d as Double = Rnd
- dim range as Integer = endIndex - startIndex
- return Round( range * d ) + startIndex
- End Function
- dim origString as String = SelText
- if origString.Trim = "" then
- print "Select some text first."
- return
- end if
- dim chars() as String = Split( origString, "" )
- dim startQuote as boolean = chars( 0 ) = """"
- dim endQuote as boolean = chars( chars.Ubound ) = """"
- if endQuote then
- chars.Remove chars.Ubound
- end if
- if chars.Ubound <> -1 and startQuote then
- chars.Remove 0
- end if
- if chars.Ubound = -1 then
- print "Select some valid text first."
- return
- end if
- dim stringToEncode as String = Join( chars, "" )
- //dim b as String = ShowDialog( "You are about to encode this string. Proceed?", stringToEncode, "Yes", "No", "" )
- //if b = "No" then
- //return
- //end if
- dim index as Integer
- dim codeArr() as String
- dim indexArr() as String
- dim addArr() as String
- dim randomizerArr() as Integer
- for index = 0 to chars.Ubound
- dim thisAdd as Integer = RndInRange( 64001, 100000 )
- codeArr.Append Str( Asc( chars( index ) ) + thisAdd )
- indexArr.Append Str( index )
- addArr.Append Str( thisAdd )
- randomizerArr.Append RndInRange( 0, chars.Ubound * 100 )
- next index
- randomizerArr.SortWith( codeArr, indexArr, addArr )
- // Construct the code
- dim eol as String = EndOfLine
- dim resultArr() as String
- resultArr.Append "// Encoding for value: "
- resultArr.Append stringToEncode
- resultArr.Append eol
- resultArr.Append "dim codeArr() as Integer = Array( "
- resultArr.Append Join( codeArr, ", " )
- resultArr.Append " )"
- resultArr.Append eol
- resultArr.Append "dim adderArr() as Integer = Array( "
- resultArr.Append Join( addArr, ", " )
- resultArr.Append " )"
- resultArr.Append eol
- resultArr.Append "dim indexArr() as Integer = Array( "
- resultArr.Append Join( indexArr, ", " )
- resultArr.Append " )"
- resultArr.Append eol
- resultArr.Append "indexArr.SortWith codeArr, adderArr"
- resultArr.Append eol
- resultArr.Append eol
- resultArr.Append "dim decodedChars() as String"
- resultArr.Append eol
- resultArr.Append "for i as Integer = 0 to codeArr.Ubound"
- resultArr.Append eol
- resultArr.Append "decodedChars.Append Chr( codeArr( i ) - adderArr( i ) )"
- resultArr.Append eol
- resultArr.Append "next i"
- resultArr.Append eol
- resultArr.Append eol
- resultArr.Append "dim decodedString as String = Join( decodedChars, """" )"
- resultArr.Append eol
- dim result as String = Join( resultArr, "" )
- SelText = result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement