Results 1 to 14 of 14

Thread: Crypted Connection , needed ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    76

    Post Crypted Connection , needed ?

    my project is file transfer ,

    what I need is a way to encrypt and decrypt the data with a key , i did try to use modRC4.bas but the the sent file is damaged !

    can you help me please ?

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Crypted Connection , needed ?

    Kinda hard to help you without seeing:

    1. Your code
    2. The encryption code
    3. What parts of the file you are encrypting and if you're decrypting those same parts
    4. How you're transferring your file
    etc...

  3. #3
    Member
    Join Date
    Jul 2006
    Posts
    47

    Re: Crypted Connection , needed ?

    Here is a basic encryption/decryption algorithm that i created that works with string variables.
    Read a chunk of the file at a time and pass it through EncryptString before sending. Then on receiving end use DecryptString on received data before writing to file.

    Code:
    Option Explicit
    
    Private Const EncKey As String = "GST5DKHGV7VH4RK&^kmG8&%87TYKhg"
    
    Public Function EncryptString(sData As String) As String
    'Encryption
    Dim keypos As Integer, i As Integer, buf As Integer
    keypos = 1
    If Len(sData) > 0 Then
        'loop for every character
        For i = 1 To Len(sData)
            'perform ascii addition
            buf = Asc(Mid(sData, i, 1)) + Asc(Mid(EncKey, keypos, 1))
                'correct buffer if it goes over ascii limit
                If buf > 255 Then
                    buf = buf - 256
                End If
                'Add to return parameter
                EncryptString = EncryptString & Chr$(buf)
            'advance keypos
            If keypos = Len(EncKey) Then
                keypos = 1
            Else
                keypos = keypos + 1
            End If
        Next i
    End If
    End Function
    
    Public Function DecryptString(sData As String) As String
    'Decryption
    Dim keypos As Integer, i As Integer, buf As Integer
    keypos = 1
    If Len(sData) > 0 Then
        'loop for every character
        For i = 1 To Len(sData)
            'perform ascii subtraction
            buf = Asc(Mid(sData, i, 1)) - Asc(Mid(EncKey, keypos, 1))
                'correct buffer if it goes over ascii limit
                If buf < 0 Then
                    buf = 256 - Abs(buf)
                End If
                'Add to return parameter
                DecryptString = DecryptString & Chr$(buf)
            'advance keypos
            If keypos = Len(EncKey) Then
                keypos = 1
            Else
                keypos = keypos + 1
            End If
        Next i
    End If
    End Function

    My ActiveX Controls Site

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Crypted Connection , needed ?

    One should keep in mind that VB String variables should not be used for binary data. There are many places where the text of a String is converted from internal Unicode to ANSI/ASCII and back. Not all of these conversions are symmetric for all possible character values, some of which binary data may tend to run into more often than plain text.

  5. #5
    Member
    Join Date
    Jul 2006
    Posts
    47

    Re: Crypted Connection , needed ?

    It depends on what sort of file is being sent. If the file is plaintext without special characters then strings are ok, however if your sending files like videos or music then you'll need to use a byte array.
    The algorithm can easily be altered to work with byte arrays instead of strings

    My ActiveX Controls Site

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    76

    Re: Crypted Connection , needed ?

    I will try yours Lozzenger ...
    Last edited by dBlues; Aug 19th, 2007 at 03:38 PM.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    76

    Re: Crypted Connection , needed ?

    thanx Lozzenger alot , it's working very well with all types of files

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    76

    Re: Crypted Connection , needed ?

    but it increases size of data alot

  9. #9
    Member
    Join Date
    Jul 2006
    Posts
    47

    Re: Crypted Connection , needed ?

    I don't see why it would increase the data size when it returns a string that's the same length as the one you passed in the function

    My ActiveX Controls Site

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Crypted Connection , needed ?

    Also be aware that if you're transferring the files by FTP, you have to specify binary transfer. ASCII transfer can modify a file.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    76

    Re: Crypted Connection , needed ?

    Quote Originally Posted by Lozzenger
    It depends on what sort of file is being sent. If the file is plaintext without special characters then strings are ok, however if your sending files like videos or music then you'll need to use a byte array.
    The algorithm can easily be altered to work with byte arrays instead of strings

    how can I modify it to work with byte arrays instead of strings?

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    76

    Re: Crypted Connection , needed ?

    Quote Originally Posted by dBlues
    how can I modify it to work with byte arrays instead of strings?
    thnx

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Crypted Connection , needed ?

    Is this still a question?

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    76

    Re: Crypted Connection , needed ?

    Quote Originally Posted by Hack
    Is this still a question?
    yeah, I still can't modify it to work with byte arrays instead of strings

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