Link to home
Start Free TrialLog in
Avatar of dbommu
dbommu

asked on

Encrypting a PIN

If any one of you can let me know how to encrypt a PIN using visual basic please let me know and I will be extremly thankfull for it. Details of what I have currently tried is a bellow.

I am developing an internet based application running on windows NT Workstation 4.0. I am using Visual Basic 5.0 for the cgi. The application is running fine and the last thing that I need to do is encrypt users PIM.

I have tried to user cryptoapi but it cannot create a container and it does not work when I use it for the internet application but runs well as a single application on the same machine.

I also thought of converting other encryption programs into vb but I did not find any left and right shift bit operators in VB.

Thank you.
Yours Sincerely,
Dharmendra Bommu
Avatar of mark2150
mark2150

Left and right shift are Integer multiply and divide by 2.

M

Don't remember where I got this but give it a try. Key value should be a four digit number.

    Public Function EncryptFile(ByVal NewTxt As String, ByVal Key As String)
    Dim i As Long
    Dim j As Long
    Dim n As Long
    Dim char As String
    Dim strText As String

        strText = NewTxt

        For i = 1 To Len(strText)
            ' Get each character in turn
            char = Mid$(strText, i, 1)
             
            ' Convert the valid ASCII values to ENCODER values
            If Asc(char) > 31 And Asc(char) < 127 Then
                n = Asc(char) - 31
            ElseIf Asc(char) > 160 And Asc(char) < 256 Then
                n = Asc(char) - 65
            ElseIf Asc(char) = 9 Then
                n = 191
            ElseIf Asc(char) = 10 Then
                n = 192
            ElseIf Asc(char) = 13 Then
                n = 193
            End If
             
            ' Add the position and the value of the key
            n = n + i + Key
             
            ' Subtract 193 until 1 < n < 193
            Do
                If n > 190 Then
                    n = n - 190
                Else
                    Exit Do
                End If
            Loop
             
            ' Convert the ENCODER value to ASCII value
            If n > 0 And n < 96 Then
                Mid$(strText, i, 1) = Chr(n + 31)
            ElseIf n > 95 And n < 191 Then
                Mid$(strText, i, 1) = Chr(n + 65)
            ElseIf n = 191 Then
                Mid$(strText, i, 1) = Chr(9)
            ElseIf n = 192 Then
                Mid$(strText, i, 1) = Chr(10)
            ElseIf n = 193 Then
                Mid$(strText, i, 1) = Chr(13)
            End If
        Next i
    EncryptFile = strText
    End Function

    Public Function DecryptFile(ByVal strText As String, ByVal Key As String)
    Dim i As Long
    Dim j As Long
    Dim n As Long
    Dim char As String
        For i = 1 To Len(strText)
            ' Get each character in turn
            char = Mid$(strText, i, 1)
         
            ' Convert the ASCII value to ENCODER value
            If Asc(char) > 31 And Asc(char) < 127 Then
                n = Asc(char) - 31
            ElseIf Asc(char) > 160 And Asc(char) < 256 Then
                n = Asc(char) - 65
            ElseIf Asc(char) = 9 Then
                n = 191
            ElseIf Asc(char) = 10 Then
                n = 192
            ElseIf Asc(char) = 13 Then
                n = 193
            End If
             
            ' Subtract the position and the value of the key
            n = n - i - Key
             
            ' Add 193 until 1 < n < 193
            Do
                If n < 1 Then
                    n = n + 190
                Else
                    Exit Do
                End If
            Loop
         
            ' Convert the ENCODER value to ASCII value
            If n > 0 And n < 96 Then
                Mid$(strText, i, 1) = Chr(n + 31)
            ElseIf n > 95 And n < 191 Then
                Mid$(strText, i, 1) = Chr(n + 65)
            ElseIf n = 191 Then
                Mid$(strText, i, 1) = Chr(9)
            ElseIf n = 192 Then
                Mid$(strText, i, 1) = Chr(10)
            ElseIf n = 193 Then
                Mid$(strText, i, 1) = Chr(13)
            End If
        Next i
        DecryptFile = strText
    End Function

Avatar of dbommu

ASKER

I am more looking for a one way hash function or any of the standard encryption methods such as md5 hash algorithm or a RSA algorithm. If you have any such program in visual basic 5.0 please mail it to me.
Thanks
Dharmendra Bommu
ASKER CERTIFIED SOLUTION
Avatar of Kory
Kory

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial