Generate 12 character passkey from DateOfBirth and ZipCode

I am using VBScript and want some code that can generate a 12 character passkey using strDateOfBirth and strZipCode.

strDateOfBirth will be in format ddmmyyyy so 29/03/2004 would be 29032004.
This string will be a fixed length of 8 characters.

strZipCode will be of variable length and format as it could be a Zip/Post code from any where around the world.

I want the process to be reversible so given the 12 character (alphanumeric) passkey I can get the original DOB and Postcode from it.
LVL 1
holgraveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ShauliCommented:
'in form declaration area
Dim strDateOfBirth As String, strZipCode As String

'in command button or where you want to activate functions
Private Sub Command1_Click()
Dim strPassKey As String
strDateOfBirth = Format(Text1.Text, "ddmmyyyy")
strZipCode = Text2.Text

'activate function to build passkey
strPassKey = Build_PassKey(strDateOfBirth, strZipCode)
MsgBox strPassKey

'activate sub to reverse passkey
Call Reverse_PassKey(strPassKey)
 MsgBox "DOB: " & strDateOfBirth & ",  ZipCode: " & strZipCode
End Sub

'function to build passkey
Public Function Build_PassKey(ByVal fnDOB As String, fnZipCode As String) As String
Dim dayOfBirth As String, monthOfBirth As String, yearOfBirth As String
'get initial data
dayOfBirth = Left(fnDOB, 2)
monthOfBirth = Mid(fnDOB, 3, 2)
yearOfBirth = Right(fnDOB, 4)
'set day to one character
If dayOfBirth > 9 Then dayOfBirth = UCase(Chr(Val(dayOfBirth) + 55))

Build_PassKey = dayOfBirth & Hex(monthOfBirth) & yearOfBirth & Format(Replace(fnZipCode, Chr(32), ""), "000000")
End Function

'sub to reverse passkey
Public Sub Reverse_PassKey(ByVal fnPassKey As String)
Dim dayOfBirth As String, monthOfBirth As String, yearOfBirth As String, zLoop As Integer
'get initial data
dayOfBirth = Left(fnPassKey, 1)
monthOfBirth = Mid(fnPassKey, 2, 1)
yearOfBirth = Mid(fnPassKey, 3, 4)
'reverse day of birth
If Not IsNumeric(dayOfBirth) Then dayOfBirth = Asc(UCase(dayOfBirth)) - 55
'reverse DOB
strDateOfBirth = dayOfBirth & "/" & Str(monthOfBirth) & "/" & yearOfBirth
'reverse zip
strZipCode = Right(fnPassKey, 6)
For zLoop = 1 To 6
    If Left(strZipCode, 1) = "0" Then strZipCode = Right(strZipCode, Len(strZipCode) - zLoop)
Next zLoop
End Sub

S
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ShauliCommented:
One correction in the sub to reverse :)

Public Sub Reverse_PassKey(ByVal fnPassKey As String)
Dim dayOfBirth As String, monthOfBirth As String, yearOfBirth As String, zLoop As Integer
'get initial data
dayOfBirth = Left(fnPassKey, 1)
monthOfBirth = Mid(fnPassKey, 2, 1)
yearOfBirth = Mid(fnPassKey, 3, 4)
'reverse day of birth
If Not IsNumeric(dayOfBirth) Then dayOfBirth = Asc(UCase(dayOfBirth)) - 55
'reverse DOB
strDateOfBirth = dayOfBirth & "/" & Val("&H" & monthOfBirth) & "/" & yearOfBirth   '<<< here the correction
'reverse zip
strZipCode = Right(fnPassKey, 6)
For zLoop = 1 To 6
    If Left(strZipCode, 1) = "0" Then strZipCode = Right(strZipCode, Len(strZipCode) - zLoop)
Next zLoop
End Sub

S

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

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.