Solved

Encryption

Posted on 2003-11-26
13
368 Views
Last Modified: 2012-05-04
Im a total newbie to Encryption im looking for the most simple way to encrypt and decrypt values with a cipher string no less than 128 i would like to use blowfish if possible. Im looking for very efficient module driven code because of the frequency that this will be used. The data will be stored in a databse.

Thank you in advance.
Greg
0
Comment
Question by:gharman
  • 7
  • 4
13 Comments
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9823713
If you need realy simple algorythm then try to use this:

Create new project, add two listboxes, and two textboxes.
Paste this code.

To use this, enter your password in textbox1 and doubleclick on line in listbox1. After that, an encrypted text will appear in listbox2.
Double click on listbox2 item to get the decrypted text again in textbox2.

NOTE that this is maybe the most simple way to use password for encryption. It is very easy to break it, but it can be used for some simple things. (Like preventing your brother from reading your text files :) )

--------------------------------------------------------
Private Sub Form_Load()
    For X = 1 To 20
        List1.AddItem X & " Some text"
    Next X
End Sub

Private Sub List1_DblClick()
    Dim NewString As String
    NewString = Encrypt(List1.List(List1.ListIndex), Text1.Text)
    List2.AddItem NewString
End Sub

Function Encrypt(strText As String, strPassword As String)
    Dim PassLen As Integer
    Dim TextLen As Integer
    Dim TextChar As String
    Dim PassCharNum As Integer
    Dim PassChar As String
    Dim NewCharCode As Integer
    Dim newText As String
   
    PassLen = Len(strPassword)
    TextLen = Len(strText)
    PassCharNum = 1
   
    For X = 1 To TextLen
        TextChar = Mid(strText, X, 1)
        PassChar = Mid(strPassword, PassCharNum, 1)
        NewCharCode = Asc(TextChar) + Asc(PassChar)
        If NewCharCode > 255 Then NewCharCode = NewCharCode - 255
        newText = newText & Chr(NewCharCode)
        PassCharNum = PassCharNum + 1
        If PassCharNum > PassLen Then PassCharNum = 1
    Next X
   
    Encrypt = newText
End Function

Private Sub List2_DblClick()
    Dim NewString As String
    NewString = Decrypt(List2.List(List2.ListIndex), Text1.Text)
    Text2.Text = NewString
End Sub

Function Decrypt(strText As String, strPassword As String)
    On Error Resume Next
   
    Dim PassLen As Integer
    Dim TextLen As Integer
    Dim TextChar As String
    Dim PassCharNum As Integer
    Dim PassChar As String
    Dim NewCharCode As Integer
    Dim newText As String
   
    PassLen = Len(strPassword)
    TextLen = Len(strText)
    PassCharNum = 1
   
    For X = 1 To TextLen
        TextChar = Mid(strText, X, 1)
        PassChar = Mid(strPassword, PassCharNum, 1)
        NewCharCode = Asc(TextChar) - Asc(PassChar)
        If NewCharCode < 0 Then NewCharCode = 255 - NewCharCode
        newText = newText & Chr(NewCharCode)
        PassCharNum = PassCharNum + 1
        If PassCharNum > PassLen Then PassCharNum = 1
    Next X
   
    Decrypt = newText

End Function


0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9823724
If you need more advenced methods try this as your starting point:

http://www.example-code.com/vb/aes.asp

0
 
LVL 11

Accepted Solution

by:
dbrckovi earned 200 total points
ID: 9823742
0
 

Author Comment

by:gharman
ID: 9823757
I was just gonna post a comment asking how i got that. Thanks a lot. Im going to see if this works now.

Thanks

Greg
0
 

Author Comment

by:gharman
ID: 9823772
IF this Chilkasoft something that has to be distrabuted with the application and how does the licensing work for it?

Greg
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9823825
This version is a 30 days trial. After that you have to buy it.

You should distribute and register ChilkatCrypt.dll with your app, but any install wizard should be able to do this for you.
Before doing that read a license.txt and other txt files for more information.

Basicaly it says that you can use this software, and distribute it with your app only if you have bought it and if your app is not based on this component.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 28

Expert Comment

by:vinnyd79
ID: 9824894
There is a good encryption library here that makes it easy to implement many popular Algorithms:

http://www.freevbcode.com/ShowCode.Asp?ID=3779

0
 

Author Comment

by:gharman
ID: 9829784
The Chilkasoft seems to work great only access does not store the string properly it cuts off two non printing characthers at the end of each string. Anyone have any ideas on this. If there is a better database format to use im all ears now would be the time to change it if i am going to. I am just familar with the MS Jet 4.0 and its easy. Thanks in advance.

Greg
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9830197
I never used databases so I can't help you much in this field, but i'll try some blind shots.

Try storing ascii values of two last characters, and then reattach them when you need them, or try storing the whole string as an array of ascii values. I don't know if there is a function that already does this but try this:

This will store a string to a ascii array
---------------------------------------
    Dim asciiArray() As Integer
    Dim Length As Integer
   
    Length = Len(strText)
       
    ReDim asciiArray(Length - 1) As Integer
       
    For x = 1 To Length
        asciiArray(x - 1) = Asc(Mid(strText, x, 1))
    Next x

    For x = 0 To UBound(asciiArray)
        Print asciiArray(x)
    Next x
------------------------------------------------------------
0
 

Author Comment

by:gharman
ID: 9830243
I have tried inputting the data manually into the database but it cuts off the last two characters.  Can you please show me how to trim a string. I want to trim the last two characters from the end of the string. This should solve my problem.

Greg
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9830276
NewString = Right(strText, 2)                            -> to get the last two characters
NewString = Left(strText, Len(strText) - 2)         -> to get evrything except the last two characters
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 10171906
Thanx
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now