8 Replies - 3265 Views - Last Post: 11 December 2010 - 10:42 PM

#1 Nitish4uall   User is offline

  • New D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 26
  • Joined: 19-April 06

Encrypt-Decrypt File with Password

Posted 26 May 2006 - 01:41 AM

Description: 'Add a CoommandButton - Command1 'Just Run and select click the button to see the action.Encryption and Decryption of any file with a password.
Sub FileEncodeAndDecode(InputFile As String, OutputFile As String, PasswordKey As String)
    
    Dim temp As Single
    Dim Char As String * 1
    Dim XORMask As Single
    Dim temp1 As Integer
    
    Open InputFile For Binary As #1
    Open OutputFile For Binary As #2
    
    For x = 1 To Len(PasswordKey)
        temp = Asc(Mid$(PasswordKey, x, 1))
        For y = 1 To temp
            temp1 = Rnd
        Next y
        
        ' Re-seed to throw off prying eyes
        Randomize temp1
    Next x
        
    
    Counter = 0
    For z = 1 To FileLen(InputFile)
        
        'Generate random mask
        XORMask = Int(Rnd * 256)
        
        'Get the char & change it
        Get 1, , Char
        Char = Chr$((Asc(Char) Xor XORMask))
        Put 2, , Char
        
        Counter = Counter + 1
        If Counter > Len(PasswordKey) Then Counter = 1
        
        ' Pull random numbers from the hat
        For x = 1 To (Asc(Mid$(PasswordKey, Counter, 1)) * 2)
            temp = Rnd
        Next x
    Next z


    Close #1
    Close #2
    
End Sub

Private Sub Command1_Click()

Dim InputFile As String
    Dim OutputFile As String
    Dim PasswordKey As String
    
    InputFile = InputBox("Enter a filename to encode")
    OutputFile = InputBox("Enter the new filename this will         become ")
    PasswordKey = InputBox("Enter the password (key)")
    
    Call FileEncodeAndDecode(InputFile, OutputFile, PasswordKey)
    
    MsgBox "File written to " + OutputFile
    End
End Sub

Private Sub Form_Load()

Command1.Caption = "Code/Decode"

End Sub





Is This A Good Question/Topic? 0
  • +

Replies To: Encrypt-Decrypt File with Password

#2 josejn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 22-February 09

Re: Encrypt-Decrypt File with Password

Posted 22 February 2009 - 11:49 AM

Nice code. Very usefull.
Was This Post Helpful? 0
  • +
  • -

#3 Neku   User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 269
  • Joined: 21-May 09

Re: Encrypt-Decrypt File with Password

Posted 23 May 2009 - 08:58 AM

but how i decode it?
Was This Post Helpful? 0
  • +
  • -

#4 zeeplax   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 07-July 09

Re: Encrypt-Decrypt File with Password

Posted 07 July 2009 - 06:24 AM

Hahaha ... Simple 'n helpfull
Was This Post Helpful? 0
  • +
  • -

#5 syedbilal   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 06-October 09

Re: Encrypt-Decrypt File with Password

Posted 06 October 2009 - 04:38 PM

how to decode it
Was This Post Helpful? 0
  • +
  • -

#6 Nitish4uall   User is offline

  • New D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 26
  • Joined: 19-April 06

Re: Encrypt-Decrypt File with Password

Posted 07 October 2009 - 12:02 AM

Use the encoded file as input, enter a new filename for output and the password.
Was This Post Helpful? 0
  • +
  • -

#7 jkbart   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 20-December 09

Re: Encrypt-Decrypt File with Password

Posted 20 December 2009 - 06:38 AM

I tried many times but with pdf filed the decoding not work. Can I do something else ? thx
Was This Post Helpful? 0
  • +
  • -

#8 jkbart   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 20-December 09

Re: Encrypt-Decrypt File with Password

Posted 20 December 2009 - 06:39 AM

sorry: not "filed" but "files"
Was This Post Helpful? 0
  • +
  • -

#9 dhan547   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 17-October 10

Re: Encrypt-Decrypt File with Password

Posted 11 December 2010 - 10:42 PM

i cant understand "file path"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1