Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Technical Support » Renegade Client » APGAR cipher to C#/VB.Net
APGAR cipher to C#/VB.Net [message #368928] Sun, 25 January 2009 17:28 Go to next message
halo2pac is currently offline  halo2pac
Messages: 659
Registered: December 2006
Location: Near Cleveland, Ohio
Karma: 0
Colonel
A few others and I are attempting to convert the XWISP APGAR Cipher into C#/Vb.Net, we are very close but are stuck.

We need to Convert this:
Perl:
sub apgar_enc {
  my @v = map ord, split //, shift;
  my @r;
  my $U="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
  for (my $i = 0; $i < 8; $i++) {
    my $a = $v[$i];
    my $index=(($a & 1
                ? $a << ($a & 1) & $v[8-$i]
                : $a ^ $v[8-$i])
                & 0x3f);
    push @r, substr($U,$index,1)
  }
  join '', @r;
}


Into VB.Net or C#.

I have attempted both, resulting on a circle of problems.

My VB.Net Tries:

#1
"CODE"


#2

"CODE"


#3
"CODE"






C# - By Aca20031
"CODE"


C# Mixed mine and Aca's
#1
"CODE"


#2
"CODE"


#3
"CODE"


#4
"CODE"


Dave's C# Code:

"CODE"


small rainbow table of values:

Pass entered | APGAR | What Aca's (#1) code does
aaaaaaaa aaaaaaaa abbbbbbb
aaaaaaa1 aaaaaaaG abbbbbbH
zzzzzzzz 6aaaaaaa 6aaaaaaa
password WaIMMsbf WaINNtbf
AbCdEfGh akgcacck akhcbcdk
99999999 aWWWWWWW aXXXXXXX
chicken1 azcecchG azcfddhG



We would really appreciate if Blazer, DanPaul, or anyone could help.


http://img339.imageshack.us/img339/1991/nefobbygenyunoreleasere.jpg
Rene-Buddy | Renegade X
Join the fight against Obsessive-Compulsive Posting Disorder. Cancel is ur friend.
*Renegade X Dev Team Member*

[Updated on: Sun, 25 January 2009 17:32]

Report message to a moderator

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 next message
CarrierII is currently offline  CarrierII
Messages: 3804
Registered: February 2006
Location: England
Karma: 0
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
Re: APGAR cipher to C#/VB.Net [message #369026 is a reply to message #368997] Mon, 26 January 2009 14:09 Go to previous message
halo2pac is currently offline  halo2pac
Messages: 659
Registered: December 2006
Location: Near Cleveland, Ohio
Karma: 0
Colonel
CarrierII wrote on Mon, 26 January 2009 09:30

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

thought that was some sort of Perl escape thingy.

CarrierII wrote on Mon, 26 January 2009 09:30

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.


ya I was wondering why there was an 8. (this is why im not coding my stuff in perl :S)

CarrierII wrote on Mon, 26 January 2009 09:30

Fourth, a small optimization: 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.

beautiful! I think I tried that at some point (i didnt paste all 600 attempts :S) but I screwed up on other areas.

CarrierII wrote on Mon, 26 January 2009 09:30

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

IT WORKS! Very Happy

CarrierII wrote on Mon, 26 January 2009 09:30

Hope that helps Wink

Immensely.


CarrierII wrote on Mon, 26 January 2009 09:30

CarrierII's brother (ahydra)

Well thank you very much ahydra.

This has to be the toughest thing I have ever attempted to code.

Also thanks much to the following people who helped me and aca20031:
Roshambo
Zack
Dave
Ghostshaw
... I hope I am not forgetting anyone.. if i am... pm me and I will thank you xD


http://img339.imageshack.us/img339/1991/nefobbygenyunoreleasere.jpg
Rene-Buddy | Renegade X
Join the fight against Obsessive-Compulsive Posting Disorder. Cancel is ur friend.
*Renegade X Dev Team Member*

[Updated on: Mon, 26 January 2009 14:12]

Report message to a moderator

Previous Topic: Ports
Next Topic: Unable to install
Goto Forum:
  


Current Time: Wed Nov 27 18:56:14 MST 2024

Total time taken to generate the page: 0.01254 seconds