Re: APGAR cipher to C#/VB.Net [message #368997 is a reply to message #368928] |
Mon, 26 January 2009 08:30 |
|
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
CarrierII's brother (ahydra)
Renguard is a wonderful initiative
Toggle Spoiler
BBC news, quoting... |
Supporters of Proposition 8 will argue California does not discriminate against gays, as the current law allows them to get married - as long as they wed a partner of the opposite sex.
|
halokid wrote on Mon, 11 October 2010 08:46 |
R315r4z0r wrote on Mon, 11 October 2010 15:35 |
|
the hell is that?
|
|
|
|