Results 1 to 7 of 7

Thread: Encrypting a text file...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    22
    I need to know a good method of encrypting a simple text file

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    You come up with your own algorithm, and then just run through the file.
    Algorithms are usually based on some maths thing.

    Eg. RSA is based on modular arithmetic.

    - jamie
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Addicted Member
    Join Date
    Feb 2001
    Posts
    198
    What do you mean by 'good'?
    Do you mean that the encryption is almost completely secure, or do you want an easy and quick way to hide data from the casual observer?

    If you want a reasonably secure algorithm, EnDcryptFile makes a mess of your file, call EnDcryptFile again (with the same password) and it will put it back together again.

    This encryption CAN be broken, although it is secure if the password is random and at least as long as the file content.

    Public Sub EnDcryptFile(Filename As String, password As String)
    Dim filenum As Integer
    Dim filedata As String
    filenum = FreeFile
    On Error Resume Next
    Open Filename For Binary As #filenum
    filedata = Space$(LOF(filenum))
    Get #1, , filedata
    Seek #filenum, 1
    Put #1, , EnDcrypt(filedata, password)
    Close #filenum
    End Sub

    Public Function EnDcrypt(inputstr As String, Pword As String) As String
    Dim pStr As String
    Dim mUpDown As Boolean
    Dim ix As Long
    Dim jx As Long

    mUpDown = True
    pStr = inputstr
    jx = 0
    For ix = 1 To Len(pStr)
    jx = jx + 1
    If jx = Len(Pword) Then jx = 1
    mUpDown = Not mUpDown
    If mUpDown Then
    Mid$(pStr, ix, 1) = Chr$(Asc(Mid$(pStr, ix, 1)) Xor Asc(Mid$(Pword, jx, 1)) + 1)
    Else
    Mid$(pStr, ix, 1) = Chr$(Asc(Mid$(pStr, ix, 1)) Xor Asc(Mid$(Pword, jx, 1)) - 1)
    End If
    Next ix
    EnDcrypt = pStr
    End Function

  4. #4
    Guest
    Encrypting in VB s very slow. Unless there only a few small files then you can use VB but its best to use something written in something like C++, which, if in the form of a dll can be called from a vb program. The following link is to blowfish encryption. In vb, it takes 90 seconds to encrypt a 2.5mb file, but using the dll on this page, it is done in 3:


    http://www.di-mgt.com.au/crypto.html#BlowfishVB

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well, here is how to do it using RSA.
    It is extremely secure.
    The code is in Mathematica format, but its easy to convert.

    Code:
    message = ToCharacterCode["HOW COMES I AM SITTING HERE DOING THIS ETEST?"];
    p = 251;
    PrimeQ[p]
    q = 953;
    PrimeQ[q]
    n = p * q;
    m = EulerPhi[n];
    e = 293;
    GCD[e, m];
    {e, n}
    encrypt[m_, e_, n_] :=
    	Module[{f},
    		f = Function[b, PowerMod[b, e, n]];
    		Map[f, m]
    	];
    makeDecryptKey[e_, p_, q_] :=
    	Module[{m = (p - 1)*(q - 1)},
    		PowerMod[e, EulerPhi[m] - 1, m]
    	];
    dKey = makeDecryptKey[e, p, q]
    cm = encrypt[message, e, n]
    decrypt[cm_, d_, n_] :=
    	Module[{f},
    		f = Function[b, PowerMod[b, d, n]];
    		Map[f, cm]
    	];
    FromCharacterCode[decrypt[cm, dKey, n]]
    - jamie
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6
    Addicted Member
    Join Date
    Aug 2000
    Posts
    181

    Question How to do this??

    Could you give an example of converting this, cos I can't seem to work it out... a description of variables would also be nice???

    Ad

  7. #7
    Guest
    Try looking up "Encryption" at www.planet-source-code.com. You'll find many examples.

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