Results 1 to 11 of 11

Thread: Encryption a Text file ?

  1. #1

    Thread Starter
    Addicted Member mfurqan's Avatar
    Join Date
    Oct 2005
    Location
    Pakistan
    Posts
    176

    Lightbulb Encryption a Text file ?

    can VB6 encrypt and later decrypt a text file so file can only be run in my program ?
    Muhammad Furqan Attari.

  2. #2
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Encryption a Text file ?

    Yes it can. You can use this function to encrypt/decrypt a string:
    VB Code:
    1. Public Function RndCrypt(ByVal Str As String, ByVal Password As String) As String
    2.     Dim SK As Long, K As Long
    3.         ' init randomizer for password
    4.     Rnd -1
    5.     Randomize Len(Password)
    6.     ' (((K Mod 256) Xor Asc(Mid$(Password, K, 1))) Xor Fix(256 * Rnd)) -> makes sure that a
    7.     ' password like "pass12" does NOT give the same result as the password "sspa12" or "12pass"
    8.     ' or "1pass2" etc. (or any combination of the same letters)
    9.         For K = 1 To Len(Password)
    10.         SK = SK + (((K Mod 256) Xor Asc(Mid$(Password, K, 1))) Xor Fix(256 * Rnd))
    11.     Next K
    12.    
    13.     ' init randomizer for encryption/decryption
    14.     Rnd -1
    15.     Randomize SK
    16.    
    17.     ' encrypt/decrypt every character using the randomizer
    18.     For K = 1 To Len(Str)
    19.         Mid$(Str, K, 1) = Chr(Fix(256 * Rnd) Xor Asc(Mid$(Str, K, 1)))
    20.     Next K
    21.    
    22.     RndCrypt = Str
    23. End Function
    So you can encrypt the text file, then print it to a txt file and when reading it in your program, decrypt it.
    Hope this helps,
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  3. #3
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Encryption a Text file ?

    Quote Originally Posted by shirazamod
    So you can encrypt the text file, then print it to a txt file and when reading it in your program, decrypt it.
    Hope this helps,
    the module cannot encrypt/decrypt a large text file.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  4. #4
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: Encryption a Text file ?

    there is a code in the codebank for creating unbreakable code. have a look at it.

  5. #5
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Encryption a Text file ?

    the module cannot encrypt/decrypt a large text file.
    Modpluz, could you please throw some more light on why the code posted by Shirazamod won't encrypt/decrypt large text files?

    I just don't have any knowledge in encryption & decryption.

    Thanks,

    Arpan

  6. #6
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: Encryption a Text file ?

    http://www.vbforums.com/showthread.php?t=368001
    Thats to the "Unbreakable" code, it would need alot of modifying to work for your needs, but the principals of unbreakable code are there.

    Also, do a quick search of the codebank for "encryption" you should get many results
    Zeegnahtuer?

  7. #7
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Encryption a Text file ?

    Arpan, do you mind running it?

    with a large text file...
    Last edited by modpluz; Nov 26th, 2005 at 05:48 PM.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  8. #8
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Encryption a Text file ?

    Quote Originally Posted by shirazamod
    Yes it can. You can use this function to encrypt/decrypt a string:

    So you can encrypt the text file, then print it to a txt file and when reading it in your program, decrypt it.
    Hope this helps,
    shirazamod, Next time you copy and paste my code, can specify that it was made by me ?
    Or you can simply post the link to the original thread, like this:
    VB - 31 Bit Encryption function

    It's really not nice when pasting someone else's code, withought posting who's the creator for it...

    And modpluz is rignt, you should not use my encryption if the file is over aproximatelly 1 MByte...
    In order to encrypt the file with my encryption you have to load the whole file at once to encrypt it.
    That's assuming you don't know how to load and encrypt with small buffers. But if you do know how to work with buffers, then I see no problem in using my code with any size of file.
    Last edited by CVMichael; Nov 26th, 2005 at 10:43 PM.

  9. #9
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Encryption a Text file ?

    Also, this is a very strong encryption that works with large files:
    VB - 128, 160 and 256 Bit File Encryption/Decryption with MD5, SHA1 and SHA256

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

    Re: Encryption a Text file ?

    I've gotten nixed for that in the past, even though I didn't remember that ROBDOG888 had posted it.

  11. #11
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: Encryption a Text file ?

    i do have a piece of code which will work on large files too. this code is actually for string compression so basically who doesnot know the underlying algorithm will find it unreadable.
    NOTE: NOT MY CODE

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