Results 1 to 18 of 18

Thread: Encryption? How?

  1. #1

    Thread Starter
    Addicted Member señorbadger's Avatar
    Join Date
    Oct 2003
    Location
    Mud pools of wellingborough
    Posts
    193

    Unhappy Encryption? How?

    Hi i have made a simple IM client server app and was wondering
    how i could encrypt the data the encryption doesn't need to be very strong

    Code would be nice but just the theroy explination is what im looking for since im confused


    Sam Lad

  2. #2
    Addicted Member Para80d's Avatar
    Join Date
    Oct 2003
    Location
    Denton, TX
    Posts
    160
    well, how simple is simple? your could just replace a with z, b with y, c with x, etc.. that's extremely simple. or you could use whatever letters you wanted. there's way better than that, but that's pretty simple.

    too simple?
    C++/VB6&.NET/QBasic/HTML/PHP/MySQL/SQLServer2k

    I'm the guy your little brother looks a lot alike. Tell your mom i said thanks.

    naked in vegas

  3. #3
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586
    Hehe my old "simple" encryption method was take the asc value of the character and add 20 to it

    It was good enough for what it was doing.. on a small business app that no one there knew how to use a computer to even look at non encrypted files anyway. They just knew how to enter the data haha.

  4. #4

    Thread Starter
    Addicted Member señorbadger's Avatar
    Join Date
    Oct 2003
    Location
    Mud pools of wellingborough
    Posts
    193

    thanks all

    thank you people


    but how do i get the key ascii values for a string varible?

    for example

    VB Code:
    1. dim msg as string
    2. dim username as string
    3.  
    4. username = "bob"
    5.  
    6.   msg = username & " says... " & txtmsg.txt
    7.      msg 'encrypt here????
    8.         Winsockout.sendData msg

  5. #5
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586
    VB Code:
    1. dim msg as string
    2. dim username as string
    3. dim i as long
    4. dim nmsg as string
    5.  
    6. username = "bob"
    7.  
    8.   msg = username & " says... " & txtmsg.txt
    9.   nmsg = ""
    10.   for i = 1 to len(msg)
    11.      nmsg = nmsg & (asc(mid(msg,i,1)) + 20)
    12.   next
    13.   msg = nmsg
    14.         Winsockout.sendData msg

    That would perform the encryption method I spoke of.

  6. #6

    Thread Starter
    Addicted Member señorbadger's Avatar
    Join Date
    Oct 2003
    Location
    Mud pools of wellingborough
    Posts
    193
    would this work for the decrpyting?
    VB Code:
    1. Dim strData As String
    2.     ' get the data and add it to the listbox
    3.     Winsock1.GetData strData
    4. for i = 1 to len(strData)
    5.      nmsg = nmsg & (asc(mid(strData,i,1)) - 20)
    6.   next
    7.   msg = nmsg
    8.  
    9. lstconvo.add item msg
    would that work???

    thanks for the code i greatly appricate it thanks mate
    thanks all

  7. #7
    Hyperactive Member csar's Avatar
    Join Date
    Mar 2002
    Location
    Siam
    Posts
    288
    I have a litte function to do this

    VB Code:
    1. Public Function EncryptText(ByVal sMessage As String, Optional ByVal nCode As Long = -1) As String
    2. Dim i As Long, sRet As String, nAscii As Long
    3.  
    4.     If Len(sMessage) = 0 Then
    5.         EncryptText = ""
    6.         Exit Function
    7.     End If
    8.    
    9.     If nCode < 0 Then
    10.         nCode = G_Shift_Char
    11.     End If
    12.    
    13.     sRet = ""
    14.     For i = 1 To Len(sMessage)
    15.         nAscii = Asc(Mid$(sMessage, i, 1)) + nCode
    16.         If nAscii >= 255 Then nAscii = nAscii - 223
    17.         sRet = sRet & Chr(nAscii)
    18.     Next i
    19.    
    20.     EncryptText = sRet
    21.  
    22. End Function
    23.  
    24. Public Function DecryptText(ByVal sCode As String, Optional ByVal nCode As Long = -1) As String
    25. Dim i As Long, sRet As String, nAscii As Long
    26.  
    27.     If Len(sCode) = 0 Then
    28.         DecryptText = ""
    29.         Exit Function
    30.     End If
    31.    
    32.     If nCode < 0 Then
    33.         nCode = G_Shift_Char
    34.     End If
    35.        
    36.     sRet = ""
    37.     For i = 1 To Len(sCode)
    38.         nAscii = Asc(Mid$(sCode, i, 1)) - nCode
    39.         If nAscii < 32 Then nAscii = nAscii + 223
    40.         sRet = sRet & Chr(nAscii)
    41.     Next i
    42.    
    43.     DecryptText = sRet
    44.  
    45. End Function

    This will shift ASCII code by specific value
    Don't leave it till tomorrow, Do It Now!
    5361726176757468204368616E63686F747361746869656E

  8. #8

    Thread Starter
    Addicted Member señorbadger's Avatar
    Join Date
    Oct 2003
    Location
    Mud pools of wellingborough
    Posts
    193
    thanks csar but my code works ok

    thanks for all ya help people

  9. #9

    Thread Starter
    Addicted Member señorbadger's Avatar
    Join Date
    Oct 2003
    Location
    Mud pools of wellingborough
    Posts
    193

    More than one client on server??

    Hi my winsock set up will only allow one user at a time could someone explain to me how i could ammend this so that many users can use the server at once

    code not nessacary just a explanation


    thanks all
    Sam Lad

  10. #10
    Fanatic Member
    Join Date
    Sep 2002
    Location
    Lexington, SC
    Posts
    586
    I'm not an expert on winsock.. heck I probably just a beginner with it but to my understanding the easiest way to allow multiple users is to create the winsock as a control array.

    Have one watching a port for connections then after that create a new array for each user that connects. Or have it setup so it tries connecting and the client changes ports until it finds an open port on the server and just stay there. Send input through the connection for what port the user is assigned to and change the winsock controls there to connect through that port. Keep up via a database or something what user is on what control array or port and then you can send messages between the ports server side to get the messages from user to another.

    This would work for a simple program like your doing. Not sure if there is a more complex way of doing it or not.

  11. #11
    Hyperactive Member sw_is_great's Avatar
    Join Date
    Nov 2003
    Posts
    330
    hey for encryption there are a lot of options :

    1. simplest : make a mapping list like a= 2, b=c and change each character like this.this is easy to decrypt

    2. find th acsii value and then add a number to it and store it.be careful when the value after adding becomes more than 255.

    3. like 2 but donnt add a fixed number , rather generate a random number and store it in the file itself at some particular position.this is a bit diff. to hack

    4. there are some standard encryption alogos available also.

    best a luck
    Regards

  12. #12
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    I use and stand by RC4 encryption, it is very secure.

  13. #13
    Member
    Join Date
    Oct 2003
    Location
    Portugal
    Posts
    49
    if you want to start from nil in encription techniques, try this:

    instead of doing a=1, b=2 try:

    convert each letter of your message to it's decimal number, and then convert the number to an binary number and then apply:

    bynary number XOR key

    key, is the password for encryption.


    E.g.(with ficticious numbers):

    Message => P
    Password (in this case just one letter) = G

    P -> 76 -> 01100010

    Do: (01100010) XOR (bynary number of G)

    and there you have an encription method for the message P.


    Did you get it ?

  14. #14
    Lively Member
    Join Date
    Mar 2003
    Posts
    68
    For multipe winsock connections, I have the same thing that StevenHickerson refers to...

    VB Code:
    1. '1st WinSock control = tcpServer
    2. '2nd WinSock control = Link() [a control array]
    3.  
    4. Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)
    5.  
    6.     Dim lIndex As Long
    7.     Dim lCount1 As Long
    8.    
    9.     'Part 1 : Check for available links (not loaded/connected)
    10.     lIndex = -1
    11.     For lCount1 = 1 To MAX_LINKS
    12.         If Me.Link.UBound < lCount1 Then Load Me.Link(lCount1)
    13.         If Not LinkConnected(lCount1) Then
    14.             lIndex = lCount1
    15.             Exit For
    16.         End If
    17.     Next lCount1
    18.  
    19.     'Part 2 : Connect the client to Link(lIndex) instead of the tcpServer that they originally contacted.
    20.     If lIndex = -1 Then
    21.         MsgBox("No more connections available")
    22.     Else
    23.         Me.Link(lIndex).Close
    24.         Me.Link(lIndex).Accept requestID
    25.     End If
    26. End Sub
    27.  
    28. Private Sub link_DataArrival(iIndex As Integer, ByVal lTotalBytes As Long)
    29.     Dim sReceiveString As String
    30.    
    31.     Me.Link(iIndex).GetData sReceiveString, vbString
    32.     'Process (iIndex indicates the client that connected)
    33. End Sub

  15. #15
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648
    Spajeoly

    Please tell me more about the RC 4 encrytion....

  16. #16
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648
    here is part of an encryption I devised that uses text hashing for any ascii values < 128

    Any comments??


    VB Code:
    1. Private sData As String
    2.  
    3.  
    4. Public Function Encrypt(Data As String, Key As String) As String
    5.     Dim byt() As Byte
    6.     Dim l As Long
    7.     Dim m As Long
    8.     Dim s As String
    9.     Dim s1 As String
    10.    
    11.     'convert to byte array
    12.     For l = 0 To Len(Data) - 1
    13.         ReDim Preserve byt(l)
    14.         byt(l) = Asc(Mid(Data, l + 1, 1))
    15.     Next
    16.    
    17.     'byt = Data
    18.    
    19.     'hash the key with the data.
    20.     For l = 0 To UBound(byt)
    21.         m = m + 1
    22.         If m > Len(Key) Then m = 1
    23.         If byt(l) < 128 Then
    24.             byt(l) = byt(l) + Asc(Mid(Key, m, 1))
    25.         End If
    26.         'l = l + 1
    27.     Next
    28.    
    29.     For l = 0 To UBound(byt)
    30.         s = s & Chr(byt(l))
    31.     Next
    32.    
    33.     Encrypt = s
    34.     sData = s
    35.     Debug.Print s
    36. End Function
    37.  
    38. Public Function Decrypt(ByVal Encrypted As String, Key As String) As String
    39.     Dim byt() As Byte
    40.     Dim l As Long
    41.     Dim m As Long
    42.     Dim s As String
    43.     Dim s1 As String
    44.  
    45.     s = Encrypted
    46.    
    47.     ReDim byt(Len(s) - 1)
    48.     m = 0
    49.     For l = 1 To Len(s)
    50.         m = m + 1
    51.         If m > Len(Key) Then m = 1
    52.         byt(l - 1) = Asc(Mid(s, l, 1))
    53.         byt(l - 1) = byt(l - 1) - Asc(Mid(Key, m, 1))
    54.         s1 = s1 & Chr(byt(l - 1))
    55.     Next
    56.    
    57.     Debug.Print s1
    58.     Decrypt = s1
    59.     sData = s1
    60. End Function
    61.  
    62.  
    63. Public Sub SaveToFile(FileName As String)
    64.     Dim l  As Long
    65.     l = FreeFile
    66.     Open FileName For Binary Access Write As #l
    67.     Put #l, 1, sData
    68.     Close #l
    69. End Sub

  17. #17
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    for encryption, everyone seems to have done something similair to what I did:
    http://acid.freewebpage.org/VB/0007.zip

    What I want to know is, how do you encrypt a file? like for instance a .jpg file.
    Have I helped you? Please Rate my posts.

  18. #18
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by Spajeoly
    I use and stand by RC4 encryption, it is very secure.
    RC4 is a good algorithm, i personally prefer AES(Advanced Encription Standard), thought its a bit slow encrypting large volume of data.

    I wrote a application which encrypts message using AES and sends throug MSN Messenger, works pretty well for me. You can use the Msn Messenger API to send and receive the messages. Just simply decrypt it before displaying and encrypt them before sending.

    You could find vb implementation of AES on the Net, if you cant i have one in my libray if you interested i can dig it out.


    Hope this helps.

    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

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