dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: text encryption, it this possible with vb?

  1. #1
    Join Date
    Jul 2002
    Location
    Newcastle, south africa
    Posts
    11

    Question text encryption, it this possible with vb?

    At run-time my program reads from numerous text files, these files are situated on my drive and are clearly visible to anyone who wishes to tamper with them, how would I encrypt my text files so that VB can still recognize them as text. the fact is that I know nothing of file encryption

    Could someone please help me on this problem
    Thank you ever so kindly.
    Hellpheric

  2. #2
    Join Date
    Aug 2001
    Posts
    1,447
    the topic of how to do encryption is endless. At its absolute most primative, you can just do a letter substitution. That is, set up an array of letters NOT in alphabetical order and then use the letters of your text as an index on that array. You'll need a reverse array to get everything back to normal.

    An even mildly determined hacker will be able to determine fairly quickly that you've used a letter substitution code and break it, but very few will even try.

  3. #3
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054
    Try this for a start:

    http://www.codeguru.com/forum/showth...hlight=encrypt

    ... then you can develop your own, or copy the code but use different encryption key.
    Marketing our skills - please participate in the survey and share your insights
    -

  4. #4
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    Simplest method:
    Code:
    private const KEY as Long = 10
    
    Function Encrypt(Value as String) as String
      dim szEncrypted as String
      dim nLen as Long, nInd as Long
      
      nLen = len(Value)
      for nInd = 1 to nLen
        szEncrypted = szEncrypted & chr(asc(mid(Value, nInd, 1)) xor KEY)
      next
    
      Encrypt = szEncrypted
    End Function
    
    Function Decrypt(Value as String) as String
      dim szDecrypted as String
      dim nLen as Long, nInd as Long
      
      nLen = len(Value)
      for nInd = 1 to nLen
        szDecrypted = szDecrypted & chr(asc(mid(Value, nInd, 1)) xor KEY)
      next
    
      Decrypt = szDecrypted
    End Function
    If you pass in "Brandon_A" to the Encrypt() function, you'll get back "HxkdnedUK". If you pass the result into Decrypt() you'll get back "Brandon_A"

    -Cool Bizs

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)