Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Technical Support » Renegade Client » APGAR cipher to C#/VB.Net
Re: APGAR cipher to C#/VB.Net [message #368997 is a reply to message #368928] Mon, 26 January 2009 08:30 Go to previous messageGo to previous message
CarrierII is currently offline  CarrierII
Messages: 3804
Registered: February 2006
Location: England
Karma:
General (3 Stars)

I think this will work in VB:

    Private Function apgar(ByVal pass As String) As String
        If pass.Length = 8 Then
            Dim v(7)
            Dim j As Integer
            For j = 0 To 7
                v(j) = pass.Substring(j, 1)
            Next

            Dim r As String = "" '  my @r;

            Dim U As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"
            Dim i As Integer
            For i = 0 To 7
                Dim t1 as integer
                If i = 0 Then
                  t1 = 0
                Else
                  t1 = Asc(v(8 - i))
                End If
                Dim a As String = v(i)
                Dim temp As Long
                If (Asc(a) And 1) Then
                    temp = (Asc(a) << 1) And t1
                Else
                    temp = Asc(a) Xor t1
                End If
                Dim index As Integer = (temp And 63)
                r &= U.Substring(index, 1) 'push @r, substr($U,$index,1)
            Next

            Return r
        End If
    End Function


First you missed the ./ off the end of the string U. It needs to be 64 characters long.

Second, the "7 - i" should have read "8 - i" like in the original Perl.

Third, the "8-$i" in the original Perl points to the null terminator when $i is zero (for a string s that is 8 characters long, s[8] returns the null terminator). So Asc(8-i) when i = 0 needs to return 0, as in my revised version.

Fourth, a small optimisation: since we only ever get to this line

temp = Asc(a) << (Asc(a) And 1) And Asc(v(7 - i))

if Asc(a) And 1 = 1, I replaced the former by the latter.

I tested it on some of the strings in your table and it looks to be working.

Hope that helps Wink

CarrierII's brother (ahydra)


Renguard is a wonderful initiative
Toggle Spoiler
 
Read Message
Read Message
Read Message
Previous Topic: Ports
Next Topic: Unable to install
Goto Forum:
  


Current Time: Sun Oct 27 09:16:45 MST 2024

Total time taken to generate the page: 0.00728 seconds