Jump to content
Tuts 4 You

Delphi to VB6 code conversion


tarequl.hassan

Recommended Posts

tarequl.hassan
Posted (edited)

Hi

Can anyone convert this delphi code to BV6?

procedure TKeyGen.Button1Click(Sender: TObject);
const Const_Array : array[0..7] of Char = ('e','n','c','r','y','w','e','b');
Var
StrName, Part2, Code : string;
i, AL, Last_Char  : Integer;

begin

  Code  := '' ;
  StrName := Edit1.Text;
  If StrName = '' then
  Edit2.Text := 'Enter your Name !!!'
  else
  Begin
  For i := 0 to length(StrName) - 1 do
  begin
    AL := ((Ord(StrName[i + 1]) + (i) + Length(StrName) + Ord(Const_Array[(I and 80000007)])) mod 10) + 48;
    Code := Char (AL) + Code  ;
  end;

    Last_Char := ((Length(StrName) + 112) mod 10) + 48;
 Edit2.Text := Code + Char(Last_Char);
  end;
end;

 

 

THANKS

Delphi registration code.txt

Edited by tarequl.hassan
  • 3 weeks later...
tarequl.hassan
Posted

Have anyone tried?

Posted (edited)

@tarequl.hassan

I understand this is not what you want to hear but IMHO you should try converting it on your own, instead of asking others to do so for you. It will be more rewarding. :)
I mean: the code is not that difficult to understand and with a couple of online searches you would find the way to convert it, if you already know VB6.

Personally I think you would just need the following links to understand that code.

http://www.delphibasics.co.uk/Article.asp?Name=Arrays
http://www.delphibasics.co.uk/RTL.asp?Name=ord
http://www.delphibasics.co.uk/rtl.asp?name=char

Good luck!

Regards,
Tony

 

Edited by tonyweb
  • Like 1
Posted

Try this. I'm not sure if this is correct (haven't tried).

Procedure keygen_click()

Dim enc = "encryweb"

If (Len(Text1.Text) = 0) Then
    Text2.Text = "Enter some name!"
    Exit Sub
End If

For i = 1 to Len(Text1.Text):
     code = code & Chr(Asc(Mid(Text1.Text, i + 1, 1)) + i + Len(Text1.Text) + Asc(Mid(enc, (i mod 7), 1)) + 48)
Next i

code = code & Chr(((Len(Text1.Text) + 112) mod 10) + 48)

Text2.Text = code

Also I'm not sure why there is 'mod 10' in this line:
Ord(Const_Array[(I and 80000007)])) mod 10)
String is 8 chars so 'and ' will work like 'mod' in this case and give us current 'string[i]'.

  • Thanks 1
Posted

VB6 is not 0 based ( per the' i' starting with 1, not 0 in the for loop), therefore this will not work

code = code & Chr(Asc(Mid(Text1.Text, i + 1, 1)) + i + Len(Text1.Text) + Asc(Mid(enc, (i mod 7), 1)) + 48)

it will have to be something more like this like this providing the rest works

code = code & Chr(Asc(Mid(Text1.Text, i, 1)) + (i - 1) + Len(Text1.Text) + Asc(Mid(enc, (i mod 7), 1)) + 48)

also the Delphi code reads

Code := Char (AL) + Code  ;

so shouldn't the vb6  code read

code = Chr(Asc(Mid(Text1.Text, i, 1)) + (i - 1) + Len(Text1.Text) + Asc(Mid(enc, (i mod 7), 1)) + 48) & code

 just my thoughts...

T-rad

  • Like 1
  • 3 weeks later...
Posted
On 4/30/2021 at 8:25 PM, ToMKoL said:

Try this. I'm not sure if this is correct (haven't tried).

Procedure keygen_click()

Dim enc = "encryweb"

If (Len(Text1.Text) = 0) Then
    Text2.Text = "Enter some name!"
    Exit Sub
End If

For i = 1 to Len(Text1.Text):
     code = code & Chr(Asc(Mid(Text1.Text, i + 1, 1)) + i + Len(Text1.Text) + Asc(Mid(enc, (i mod 7), 1)) + 48)
Next i

code = code & Chr(((Len(Text1.Text) + 112) mod 10) + 48)

Text2.Text = code

Also I'm not sure why there is 'mod 10' in this line:
Ord(Const_Array[(I and 80000007)])) mod 10)
String is 8 chars so 'and ' will work like 'mod' in this case and give us current 'string[i]'.

This code is not working for me. Anyone tested?

tarequl.hassan
Posted
20 hours ago, ToMKoL said:

Try this one. Tested and it should work as delphi version.

delphivb.zip 5.06 kB · 3 downloads

Thanks. But it doesn't generate the actual results. I am sending the Delphi and assembly one for checking.

Posted

@ToMKoL: I'm able to spot one mistake in your code:

Asc(Mid(enc, (i Mod 7), i))

should most likely read

Asc(Mid(enc, (i Mod 8), 1))

Maybe there are more issues, but I'm not really a VB wizard... ;) 

  • Like 1
Posted

@tarequl.hassan: I've replied to You in PM. Any compiled version will be fine to check.

@kao: Thanks for spotting error. I'm also no VB coder (this is my second program in basic). Also my Delphi coding ended over 20+ years ago with D4 so I might forgot few things and maybe read source code wrong.

Will correct mistake pointed out and upload corrected version.

tarequl.hassan
Posted
1 hour ago, ToMKoL said:

@tarequl.hassan: I've replied to You in PM. Any compiled version will be fine to check.

@kao: Thanks for spotting error. I'm also no VB coder (this is my second program in basic). Also my Delphi coding ended over 20+ years ago with D4 so I might forgot few things and maybe read source code wrong.

Will correct mistake pointed out and upload corrected version.

Please find the proggie in delphi and masm. Woul you please check?

In ASM.rar Project1.rar

Posted

There were few more small mistakes, including one in my earlier fix. :) 

This one is tested and output matches your ASM/Delphi versions.

Option Explicit
Procedure keygen_click()
    Dim enc As String
    Dim username As String
    Dim serial As String
    Dim idx1 As Integer
    Dim i As Integer
    
    enc = "encryweb"
    
    username = Text1.Text
    If (Len(username) = 0) Then
        Text2.Text = "Enter some name!"
        Exit Sub
    End If

    serial = ""
    For i = 0 To Len(username) - 1
        ' calculate magic number
        idx1 = Asc(Mid(username, i + 1, 1)) + _
            i + _
            Len(username) + _
            Asc(Mid(enc, (i Mod 8) + 1, 1))
        ' prepend the symbol to generated serial
        serial = Chr(idx1 Mod 10 + 48) & serial
    Next i
    
    ' finally, append one more symbol that depends on username length
    serial = serial & Chr(((Len(username) + 112) Mod 10) + 48)
    Text2.Text = serial
End Sub

 

  • Like 1
Posted

@tarequl.hassanPlease check snippet provided by kao. Hope that this time it will work for You.

  • Thanks 1
tarequl.hassan
Posted
2 minutes ago, ToMKoL said:

@tarequl.hassanPlease check snippet provided by kao. Hope that this time it will work for You.

I sent a mail to you with link. Have you checked?

Thanks

tarequl.hassan
Posted
18 hours ago, kao said:

There were few more small mistakes, including one in my earlier fix. :) 

This one is tested and output matches your ASM/Delphi versions.


Option Explicit
Procedure keygen_click()
    Dim enc As String
    Dim username As String
    Dim serial As String
    Dim idx1 As Integer
    Dim i As Integer
    
    enc = "encryweb"
    
    username = Text1.Text
    If (Len(username) = 0) Then
        Text2.Text = "Enter some name!"
        Exit Sub
    End If

    serial = ""
    For i = 0 To Len(username) - 1
        ' calculate magic number
        idx1 = Asc(Mid(username, i + 1, 1)) + _
            i + _
            Len(username) + _
            Asc(Mid(enc, (i Mod 8) + 1, 1))
        ' prepend the symbol to generated serial
        serial = Chr(idx1 Mod 10 + 48) & serial
    Next i
    
    ' finally, append one more symbol that depends on username length
    serial = serial & Chr(((Len(username) + 112) Mod 10) + 48)
    Text2.Text = serial
End Sub

 

Great!!! It works perfectly.

 

Thanks kao.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...