Results 1 to 3 of 3

Thread: encrypt/Decrypt a whole file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Posts
    482
    Hey, Using the code below, i want to be able to ENCRYPT a whole TEXT FILE...

    I am not sure how i would make it ENCRYPT a whole file using this, So could someone make it workable? or maybe if someone has an encryption script maybe LIKE THIS ONE or better that will encrypt a FILE/ DECRYPT

    ::USE:: I am saving a bunch of program settings, and i don't want people to edit them,, so i want my program to SAVE ALL THE SETTINGS, to the file, ENCRYPT IT, and then when i want to open it, it will DECRYPT , and Read it (I have it so i can read it)..

    THANKS ALOT
    PS: or would i have to import it all into a textbox, and then encrypt the Textbox?? THANKS- i would like to get the program to encrypt it with out textfile.. thanks again
    Code:
    '<<------------------------------------------>>
    'START EN/DE crypt PARTS
    '<<==========================================>>
    #Const CASE_SENSITIVE_PASSWORD = False
    
    Private Sub cmdEncrypt_Click()
        ' You can encrypt twice for extra security
        txtText = EncryptText((txtText), txtPassword)
        txtText = EncryptText((txtText), txtPassword)
    End Sub
    
    Private Sub cmdDecrypt_Click()
        txtText = DecryptText((txtText), txtPassword)
        txtText = DecryptText((txtText), txtPassword)
    End Sub
    
    'Encrypt text
    Private Function EncryptText(strText As String, ByVal strPwd As String)
        Dim i As Integer, c As Integer
        Dim strBuff As String
    
    #If Not CASE_SENSITIVE_PASSWORD Then
    
        'Convert password to upper case
        'if not case-sensitive
        strPwd = UCase$(strPwd)
    
    #End If
    
        'Encrypt string
        If Len(strPwd) Then
            For i = 1 To Len(strText)
                c = Asc(Mid$(strText, i, 1))
                c = c + Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
                strBuff = strBuff & Chr$(c And &HFF)
            Next i
        Else
            strBuff = strText
        End If
        EncryptText = strBuff
    End Function
    
    'Decrypt text encrypted with EncryptText
    Private Function DecryptText(strText As String, ByVal strPwd As String)
        Dim i As Integer, c As Integer
        Dim strBuff As String
    
    #If Not CASE_SENSITIVE_PASSWORD Then
    
        'Convert password to upper case
        'if not case-sensitive
        strPwd = UCase$(strPwd)
    
    #End If
    
        'Decrypt string
        If Len(strPwd) Then
            For i = 1 To Len(strText)
                c = Asc(Mid$(strText, i, 1))
                c = c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
                strBuff = strBuff & Chr$(c And &HFF)
            Next i
        Else
            strBuff = strText
        End If
        DecryptText = strBuff
    End Function

  2. #2
    Guest
    You should check http://www.planet-source-code.com for Encryption or Encrypting Files. I'm sure plenty of stuff will come up.

  3. #3
    New Member
    Join Date
    Jan 2000
    Location
    Singapore
    Posts
    10
    It's actually quite simple
    I'll explain briefly.

    Process the encrypted file, line by line,
    until you read the EOF character.

    Pass each line you read from the file,
    into the function you wrote and append
    the output to a temp string.

    The end result of the temp string is
    your decrypted text. Encryption is just
    the opposite.


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