Encoding help

1. Senior Member
Join Date
Dec 1969
Posts
2,854

## Encoding help

Hey Guys...<BR><BR>I have this function..... Trying to repair someone elses code. The below function"encodes" a passowrd to a numeric equivalent, anyone feel like having a go at reversing the Input / Output. <BR><BR>I&#039;ve been trying and its doing my head in.<BR><BR>Function KeyCode(Password)<BR> Dim tmpInt<BR> Dim tmpKeyCode<BR><BR> For tmpInt = 1 To Len(Password)<BR> Select Case (Asc(Left(Password, 1)) * tmpInt) Mod 4<BR> Case 0<BR> tmpKeyCode = tmpKeyCode + (Asc(Mid(Password, tmpInt, 1)) * tmpInt)<BR> Case 1<BR> tmpKeyCode = tmpKeyCode - (Asc(Mid(Password, tmpInt, 1)) * tmpInt)<BR> Case 2<BR> tmpKeyCode = tmpKeyCode + (Asc(Mid(Password, tmpInt, 1)) * (tmpInt - Asc(Mid(Password, tmpInt, 1))))<BR> Case 3<BR> tmpKeyCode = tmpKeyCode - (Asc(Mid(Password, tmpInt, 1)) * (tmpInt - Asc(Mid(Password, tmpInt, 1))))<BR> End Select<BR> Next<BR> KeyCode = tmpKeyCode<BR>End Function<BR><BR>Many thanks, to those who have a bash!<BR>D.

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Well...

...let&#039;s fix the crappiness of the coding, first:<BR><BR>Function KeyCode(Password)<BR> Dim tmpInt<BR> Dim tmpKeyCode<BR> tmpKeyCode = 0 &#039; no initialization before!<BR> Dim firstChar<BR> firstChar = Asc( Left( Password, 1 ) ) <BR> Dim curCh<BR> For tmpInt = 1 To Len(Password)<BR> curCh = Asc(Mid(Password,tmpInt,1))<BR> Select Case (firstChar * tmpInt) Mod 4<BR> Case 0<BR> tmpKeyCode = tmpKeyCode + (curCh * tmpInt)<BR> Case 1<BR> tmpKeyCode = tmpKeyCode - (curCh * tmpInt)<BR> Case 2<BR> tmpKeyCode = tmpKeyCode + (curCh * (tmpInt - curCh) )<BR> Case 3<BR> tmpKeyCode = tmpKeyCode - (curCh * (tmpInt - curCh) )<BR> End Select<BR> Next<BR> KeyCode = tmpKeyCode<BR>End Function<BR><BR>************<BR><BR>For the life of me, I can&#039;t see how that algorithm guarantees that you will get a unique output number for every possible input string.<BR><BR>Give me some time and I&#039;m sure I could get the same result from two different strings.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
2,854

## RE: Well...

Thanks Bill, I really appreciate your help on this, I&#039;ve been struggling with it today, and just thought a fresh pair of eyes would be a big help. If you could help me with it, I would be most grateful, but don&#039;t go out of your way! <BR><BR>Its now 1:00 Am here and I&#039;m gonna go to bed. Thanks for the help!<BR><BR>my email address if you do manage to crack it.<BR><BR>Davehlong AT btinternet DOT com<BR><BR>:-)<BR><BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•