VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Easy Code to Encrypt and Decrypt

by Raghuraja.C (12 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 2nd October 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Easy Code to Encrypt and Decrypt

Rate Easy Code to Encrypt and Decrypt



'If same string pass this function return different 
'Encryption code if decrept it returns same string
'This Function will get the string and encrypt
Public Function fcnEncrypt(valToEncrpt As String) As String

    Dim strOriVal As String
    Dim intEnCry  As String
    Dim intInc    As Integer
    Dim rndVal1   As Integer
    Dim rndVal2   As Integer
    
    strOriVal = valToEncrpt
    rndVal1 = Round(Rnd(9) * 10)
    rndVal2 = Round(Rnd(9) * 5)
    If rndVal1 = 0 Then
        rndVal1 = 4
    End If
    For intInc = 1 To Len(strOriVal)
        intEnCry = Chr(Asc(Mid(strOriVal, intInc, 1)) + rndVal1 - rndVal2) & intEnCry
    Next
    
    fcnEncrypt = Chr(rndVal1) & intEnCry & Chr(rndVal2)
    
End Function

'Please pass the Encrypted string which is going to decrept
'This Function will get the string and decrept

'To decrept the required String
Public Function fcnDecrpt(valToDecrpt As String) As String

    Dim strOriVal As String
    Dim strDeCry  As String
    Dim intInc    As Integer
    Dim rndVal1   As Integer
    Dim rndVal2   As Integer
    
    strOriVal = valToDecrpt
    
    rndVal1 = Asc(Left(strOriVal, 1))
    rndVal2 = Asc(Right(strOriVal, 1))
    
    strOriVal = Mid(strOriVal, 2, Len(strOriVal) - 2)
    
    For intInc = 1 To Len(strOriVal)
        strDeCry = Chr(Asc(Mid(strOriVal, intInc, 1)) - rndVal1 + rndVal2) & strDeCry
    Next
    
    fcnDecrpt = strDeCry
    
End Function


Download this snippet    Add to My Saved Code

Easy Code to Encrypt and Decrypt Comments

No comments have been posted about Easy Code to Encrypt and Decrypt. Why not be the first to post a comment about Easy Code to Encrypt and Decrypt.

Post your comment

Subject:
Message:
0/1000 characters