954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Cogwheel Encryption Method

By Jhai Salvador on Sep 20th, 2010 11:13 am

This is my Cogwheel Encryption Method to encrypt and decrypt strings.

Wheel1 is Replace by Wheel2 when Encrypting and Wheel2 is Replace by wheel1 when you are decrypting...

To Encrypt a string, just call the EncryptString function

Text2.Text = EncryptString(Text1.Text)


To Decrypt a string, just call the DecryptString function

Text2.Text = DecryptString(Text1.Text)


This is my First Code Snippet so hope you like it.

Option Explicit

'Valid Characters for Password
Const Wheel1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+=-{}[]:;<>,.?/"
'Replacemet For Wheel1 (Must be same with Wheel1 but make it Random)
Const Wheel2 = "89afi1jg2hbekAwxKBCFlmV=-cZrs3X#GY4.?/5tuOJ%^vyLnWzM{NP}[QR$EIoSpq;<>,T0*()67HUdD&!@_+]:"

Public Function EncryptString(xStr As String) As String
Dim xStrHolder As String
Dim xStrIndex As Integer
Dim i As Integer
For i = 1 To Len(xStr)
   xStrIndex = InStr(Wheel1, Mid(xStr, i, 1))
   If xStrIndex = 0 Then
      MsgBox "Invalid use of character!...", vbExclamation, "Invalid Character"
      Exit Function
   Else
      xStrHolder = xStrHolder & Mid(Wheel2, xStrIndex, 1)
   End If
Next i
EncryptString = xStrHolder
End Function

Public Function DecryptString(xStr As String) As String
Dim xStrHolder As String
Dim xStrIndex As Integer
Dim i As Integer
For i = 1 To Len(xStr)
   xStrIndex = InStr(Wheel2, Mid(xStr, i, 1))
   If xStrIndex = 0 Then
      MsgBox "Invalid use of character!...", vbExclamation, "Invalid Character"
      Exit Function
   Else
      xStrHolder = xStrHolder & Mid(Wheel1, xStrIndex, 1)
   End If
Next i
DecryptString = xStrHolder
End Function

Nice way of manipulating strings. There are some easier ways to encrypt and decrypt though. Nice code as well.

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 
Nice way of manipulating strings. There are some easier ways to encrypt and decrypt though. Nice code as well.

:) Thanks. Hope more will learn from it (Manipulating strings)..

jhai_salvador
Junior Poster
180 posts since Mar 2008
Reputation Points: 33
Solved Threads: 34
 

Only a pleasure. I'm sure they will learn from this.

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: