Results 1 to 5 of 5

Thread: Anyone have a good simple encryption/decrpytion function?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    Anyone have a good simple encryption/decrpytion function?

    to encrypt/decrypt a string?
    nothing fancy, just one that will work 100% and return characters that can be seen in a textbox.. (there are some functions that return really high ascii characters that are 'boxes' in textboxes... and if one was to copy that to a text file, then decrypt the data in the text file, the boxes would all decrpyt to a single character, since they all have the same ascii code)

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Anyone have a good simple encryption/decrpytion function?

    Do a search of the forums. There are many examples as the subject comes up every week. You can also search in the CodeBank, for complete solutions.

    If you want simple encryption, you could just loop through the textbox character by character. For each character, take the x=ASC() number of the key, and add a nother number to it (say 2). Then change the character to z=chr(x+2)

    This would change David into Fcxkf. Then to decrypt, just reverse the process to get David.

    VB Code:
    1. ' Encrypt
    2. dim a%,x%,z$
    3. for a=1 to len(text1.text)
    4.   x=asc(mid(text1.text,a,1))
    5.   z=chr(x+2)
    6.   mid(text1,a,1)=chr(z)
    7. next a
    8.  
    9. ' Decrypt
    10. dim a%,x%,z$
    11. for a=1 to len(text1.text)
    12.   x=asc(mid(text1.text,a,1))
    13.   z=chr(x-2)
    14.   mid(text1,a,1)=chr(z)
    15. next a

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Anyone have a good simple encryption/decrpytion function?

    Here is one I built yesterday when I was doing nothing.
    Thought it's simple, it's hard to crack without knowing the key.

    VB Code:
    1. Function Encrypt(sText As String, sKey As String) As String
    2.     Dim x As Long, i As Long, k As Long
    3.     While i < Len(sText)
    4.         Randomize                       ''Just inserts random chars so that it is hard to decrypt
    5.         If Rnd * 10 > 5 And Len(Encrypt) < Len(sText) * 2 Then ''50% chances and limit output length
    6.             x = Rnd * 20
    7.         Else
    8.             i = i + 1
    9.             x = Asc(Mid(sText, i, 1))
    10.         End If
    11.         k = k + 1
    12.         Encrypt = Encrypt & Chr(x Xor Asc(Mid(sKey, k, 1)))
    13.         If k >= Len(sKey) Then k = 1
    14.     Wend
    15. End Function
    16.  
    17. Function Decrypt(sText As String, sKey As String) As String
    18.     Dim x As Long, i As Long, k As Long
    19.     For i = 1 To Len(sText)
    20.         k = k + 1
    21.         x = Asc(Mid(sText, i, 1)) Xor Asc(Mid(sKey, k, 1))
    22.         If x > 20 Then Decrypt = Decrypt & Chr(x) ''bcoz we know upto 20 is fake chars
    23.         If k >= Len(sKey) Then k = 1
    24.      Next
    25. End Function

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: Anyone have a good simple encryption/decrpytion function?

    Check out google.
    Look for BlowFish, or something like that.
    There's VB example source codes for it, and the encryption is pretty strong.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Anyone have a good simple encryption/decrpytion function?

    Here's an example of MD5 encryption.
    This class also does other encryption like URL Encoding this MD5 encrypted data, which is handy.
    I use this is what I use in my apps. just run Data Encryption.vpg

    There is also another demo in this zip that allows you to encypt file.

    Woka
    Attached Files Attached Files

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