Results 1 to 11 of 11

Thread: Simple way to encrypt URL's

  1. #1

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Simple way to encrypt URL's

    VB Code:
    1. Private Function Encrypt(strInput As String) As String
    2.   Dim letters As String
    3.   Dim encArr() As Variant
    4.   Dim daChar As String
    5.   Dim strOutput As String
    6.  
    7.   letters = "abcdefghijklmnopqrstuvwxyz/.1234567890~_:"
    8.  
    9.   encArr = Array("%61", "%62", "c", "%64", "e", "%66", "%67", "%68", "%69", _
    10.       "%6a", "%6b", "%6c", "m", "n", "o", "%70", "%71", "%72", "%73", "t", "%75", _
    11.       "%76", "w", "%78", "%79", "%7a", "/", ".", "1", "2", "3", "4", "5", "6", "7", _
    12.       "8", "9", "0", "~", "_", "!", ":")
    13.  
    14.   For i = 1 To Len(strInput)
    15.     daChar = Mid(strInput, i, 1)
    16.    
    17.     For e = 1 To Len(letters)
    18.         If daChar = Mid(letters, e, 1) Then
    19.             strOutput = strOutput & encArr(e - 1)
    20.             Exit For
    21.         End If
    22.     Next
    23. Next
    24.  
    25. Encrypt = strOutput
    26. End Function
    27.  
    28. Private Sub cmdEncrypt_Click()
    29. txtEncryptedURL.Text = Encrypt(txtURL.Text)
    30. End Sub

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Simple way to encrypt URL's

    What does that do?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Re: Simple way to encrypt URL's

    it encodes the text

    I had this in delphi too, cant find the bugger though

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Simple way to encrypt URL's

    Quote Originally Posted by Madboy
    it encodes the text
    That function partly URL encodes the text. But URL encoding is not meant for letters and numbers it was designed to encode special characters like @, =, & etc.

    This isn't encryption eiether, it is encoding which is used to make data safe for transport over the Internet via a URL or HTTP request.

    This function encodes a URL. Notice how it only replces characters which are are not letters or numbers:
    VB Code:
    1. ' url encodes a string
    2. Function URLEncode(ByVal str As String) As String
    3.         Dim intLen As Integer
    4.         Dim X As Integer
    5.         Dim curChar As Long
    6.         Dim newStr As String
    7.                
    8.         intLen = Len(str)
    9.         newStr = ""
    10.        
    11.         ' encode anything which is not a letter or number
    12.         For X = 1 To intLen
    13.             curChar = Asc(Mid$(str, X, 1))
    14.            
    15.            
    16.             If curChar = 32 Then
    17.                 ' we can use a + sign for a space
    18.                 newStr = newStr & "+"
    19.             ElseIf (curChar < 48 Or curChar > 57) And _
    20.                 (curChar < 65 Or curChar > 90) And _
    21.                 (curChar < 97 Or curChar > 122) Then
    22.                
    23.                 newStr = newStr & "%" & Hex(curChar)
    24.             Else
    25.                 newStr = newStr & Chr(curChar)
    26.             End If
    27.         Next X
    28.        
    29.         URLEncode = newStr
    30. End Function
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Re: Simple way to encrypt URL's

    And the Delphi.......please?

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Simple way to encrypt URL's

    Quote Originally Posted by Madboy
    And the Delphi.......please?
    What delphi?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Re: Simple way to encrypt URL's

    Whats the delphi code equivelant?

  8. #8

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Re: Simple way to encrypt URL's

    Would you please help me to convert this Visual Basic code from above, so i may use it in a Delphi application?

    Thanks

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Simple way to encrypt URL's

    Remember, strings are arrays in Delphi. Use the Length function to determine the length of the string. Use its index to extract a single character you address the string like you would an array. You can use the ord function to get the ascii value of a character.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  10. #10

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Re: Simple way to encrypt URL's

    Ok, i have been on the best part of an hour trying this.
    It is absolutely boggling my brain, i am not good at converting
    But to show my efforts, and to show i actually tried on my own this is what i came up with
    As usual i get a whole bunch of errors, too many to write up here
    This is trying to convert the function you posted for VB VisualAd


    Code:
    function EncodeURL(ByVal str: String);
    var
      intLen: Integer;
      X: Integer;
      curChar: Long;
      newStr: String;
    begin
      intLen:= Length(str);
      newStr:= '';
      //encode anything which is not a letter or number
      for X:= 1 to intLen do
        curChar:= Asc(Mid$(str,X,1));
      if curChar = 32 then
        //we can use a + sign for a space
        newStr:= newStr & '+'
      else if (curChar < 48 Or curChar > 57) And (curChar < 65 Or curChar > 90) And (curChar < 97 Or curChar > 122) then
        newStr:= newStr & '%' & Hex(curChar)
      else
        newStr:= newStr & Chr(curChar)
      end
      URLEncode:= newStr;
    end;

  11. #11

    Thread Starter
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253

    Re: Simple way to encrypt URL's

    still no joy, care to help a hand?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width