encyption and decryption

hai, any of you know how to do encryption and decrytion ?
please help. i want example(source code) and explainations.

any type of encryption will do (using Visual Basic).
Who is Participating?

Improve company productivity with a Business Account.Sign Up

anzenConnect With a Mentor Commented:
Try the following code:

' Simple XOR encryption/decription
Public Function EncDec(sDataBuff As String, sKey As String) As String
    Dim iChr As Long, sTempKey As String
    Dim nDat As Integer, nKey As Integer
    Dim sOutBuff As String

    ' First create a long enough key
    sTempKey = sKey
    While Len(sTempKey) < Len(sDataBuff)
        sTempKey = sTempKey & sKey
    ' Cleanup the output buffer
    sOutBuff = vbNullString

    ' Next use the Oooold XOR method
    For iChr = 1 To Len(sDataBuff)
        nDat = Asc(Mid(sDataBuff, iChr, 1))
        nKey = Asc(Mid(sTempKey, iChr, 1))
        sOutBuff = sOutBuff & Chr(nDat Xor nKey)
    Next iChr
    ' Return the result (enc/dec)
    EncDec = sOutBuff            
End Function

this simple function use the old Xor trick to encode/decode a given buffer, call it the first time to encrypt and the second time to decrypt, the buffer and the key could contain any kind of char.

what kind of encryption are you looking for ?
Or just any ?
lohhianAuthor Commented:
just any encryption will do (use for VB).
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

lohhianAuthor Commented:
Edited text of question
use the CryptoAPI?
lohhianAuthor Commented:

can you please leave somo more comments on it.
and what i want is encryption on one code and decryption on one code.

thanks a million. Please !!.
Please explain better, what do You mean by "one code", the routine simply accepts the same code for both the operations,
if You need a "public-key" encryption method it's not that simple
and You'd better go searching for PgP on the net or getting some doc about the MS CryptoAPI !!!

My answer was for a SIMPLE encrypt/decrypt method which was what You requested !!!

lohhianAuthor Commented:
anzen, sorry for making you misunderstanding.
your code is okay, good. i like it. (i given you points :))

your example is encryption and descryption in one module, right ?

what i mean,i want is encryption in ONE MODULE and decyption in ONE MODULE.
Hmmm something like not allowing an user to encrypt (or decrypt) the data.... tell me more I'll see what to do.

P.S. You can write me directly, my mail is anzen@bolagna.crosswinds.net, let me know.
lohhianAuthor Commented:
no ... no .. okay, let me tell you one by one.

in a form, there's a text box (to key in), one ENCRYPT command box and one DECRYPT command box.

now, when the user key into the text box, the user click on the ENCRYPT command box to encypt it.

so, know what i want ?? thanks
(can i have your email adress ?, so easy to contact you)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.