Results 1 to 12 of 12
  1. #1
    Sixx93's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    673
    Reputation
    21
    Thanks
    250
    My Mood
    Cool

    Change code lenguage

    Hello guys,

    I have some problems converting 2 C++ functions in 2 vb.net ones.

    Those are the functions:

    Code:
    char* Crypt(char string[], int key)
    {
    	int length = strlen(string);
    	char* tempstring = new char[length + 1];
    	for (int i = 0; i < length; i ++)
    	{
    		int KeyStep = key + i;
    		tempstring[i] = string[i] + KeyStep;
    	}
    	tempstring[length] = 0;
    	return tempstring;
    }
    char* Decrypt(char string[], int key)
     {
    	int length = strlen(string);
    	char* tempstring = new char[length + 1];
    	for (int i = 0; i < length; i ++)
    	{
    		int KeyStep = key + i;
    		tempstring[i] = string[i] - KeyStep;
    	}
    	tempstring[length] = 0;
    	return tempstring;
    }
    I tryed to convert them in vb.net but I can't get the way to convert each char in his ASCII value in order to add the keystep and get the encrypted one:

    Code:
    Public Function Crypt(ByVal stringa() As Char, ByVal key As Integer) As String
    
            Dim length As Integer = stringa.Length
            Dim tempstring() As Char = stringa
    
            For i As Integer = 0 To length - 1
                Dim KeyStep As Integer = key + i
                tempstring(i) = stringa(i).ToString + KeyStep.ToString
            Next
    
            Return tempstring
    
        End Function
    
        Public Function Decrypt(ByVal stringa() As Char, ByVal key As Integer) As String
    
            Dim length As Integer = stringa.Length
            Dim tempstring() As Char = stringa
    
            For i As Integer = 0 To length - 1
                Dim KeyStep As Integer = key + i
                tempstring(i) = stringa(i).ToString - KeyStep.ToString
            Next
    
            Return tempstring
    
        End Function
    Moreover, in the Decrypt function, at line 22
    Code:
     tempstring(i) = stringa(i).ToString - KeyStep.ToString
    I got this error: "Error 1 Value of type 'Double' cannot be converted to 'Char'. "


    Can anyone help me?

    Thanks in advance and have a nice day

  2. #2
    nikit6000's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Location
    Russia
    Posts
    10
    Reputation
    10
    Thanks
    50
    try this
    Code:
    Public Function Crypt(ByVal stringa() As Char, ByVal key As Integer) As String
    
            Dim length As Integer = stringa.Length
            Dim tempstring() As Char = stringa
    
            For i As Integer = 0 To length - 1
                Dim KeyStep As Integer = key + i
                tempstring(i) = stringa(i).ToString + KeyStep.ToString
            Next
    
            Return tempstring
    
        End Function
    
        Public Function Decrypt(ByVal stringa() As Char, ByVal key As Integer) As String
    
            Dim length As Integer = stringa.Length
            Dim tempstring() As Char = stringa
            For i As Integer = 0 To length - 1
                Dim KeyStep As Integer = key + i
                Dim g As Double = stringa(i).ToString - KeyStep.ToString
                tempstring(i) = Convert.ToChar(g)
            Next
    
            Return tempstring
    
        End Function
    Last edited by nikit6000; 07-20-2013 at 09:39 AM.

  3. #3
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold
    @OP


    Public Function Crypt(ByVal stringa() As Char, ByVal key As Integer) As String

    Dim length As Integer = stringa.Length
    Dim tempstring() As Char = stringa '' Assigns the reference, not make a copy.

    For i As Integer = 0 To length - 1
    Dim KeyStep As Integer = key + i
    tempstring(i) = stringa(i).ToString + KeyStep.ToString '' Changes the original!
    ''^^ char = string , idk.
    Next
    Return tempstring ''Function returns String, or Char array ?
    End Function
    Last edited by abuckau907; 07-21-2013 at 11:09 PM.
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

  4. #4
    Sixx93's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    673
    Reputation
    21
    Thanks
    250
    My Mood
    Cool
    Quote Originally Posted by abuckau907 View Post
    @OP


    Public Function Crypt(ByVal stringa() As Char, ByVal key As Integer) As String

    Dim length As Integer = stringa.Length
    Dim tempstring() As Char = stringa '' Assigns the reference, not make a copy.

    For i As Integer = 0 To length - 1
    Dim KeyStep As Integer = key + i
    tempstring(i) = stringa(i).ToString + KeyStep.ToString '' Changes the original!
    ''^^ char = string , idk.
    Next
    Return tempstring ''Function returns String, or Char array ?
    End Function
    Dim tempstring() As Char = stringa

    Is done to get the same length as stringa






    tempstring(i) = stringa(i).ToString + KeyStep.ToString

    How can it changes the original?! The equation is meant to modify the tempstring.





    Return tempstring

    Your're right, I forgot to change the Function type... I was doing some tryes


    Quote Originally Posted by nikit6000 View Post
    try this
    Code:
    Public Function Crypt(ByVal stringa() As Char, ByVal key As Integer) As String
    
            Dim length As Integer = stringa.Length
            Dim tempstring() As Char = stringa
    
            For i As Integer = 0 To length - 1
                Dim KeyStep As Integer = key + i
                tempstring(i) = stringa(i).ToString + KeyStep.ToString
            Next
    
            Return tempstring
    
        End Function
    
        Public Function Decrypt(ByVal stringa() As Char, ByVal key As Integer) As String
    
            Dim length As Integer = stringa.Length
            Dim tempstring() As Char = stringa
            For i As Integer = 0 To length - 1
                Dim KeyStep As Integer = key + i
                Dim g As Double = stringa(i).ToString - KeyStep.ToString
                tempstring(i) = Convert.ToChar(g)
            Next
    
            Return tempstring
    
        End Function
    The first Function is the same as mine one wich doesn't works...
    The second function doesn't works:

    vzx(the string to decrypt) -> Invalid cast from string "v" to type 'Double'.

    I got this arror at this line (of course): Dim g As Double = stringa(i).ToString - KeyStep.ToString

    ---------- Post added at 11:27 AM ---------- Previous post was at 11:06 AM ----------

    Omg I'm so stupid...
    I solved this problem just converting the char of the original string to his corresponding ascii value, then added the key step and finally converted the sum in a char.

    If anyone need them, those are the function:

    Code:
    Public Function Crypt(ByVal stringa() As Char, ByVal key As Integer) As String
    
            Dim length As Integer = stringa.Length
            Dim tempstring() As Char = stringa
    
            For i As Integer = 0 To length - 1
                Dim KeyStep As Integer = key + i
                tempstring(i) = Chr(Asc(stringa(i)) + KeyStep)
            Next
    
            Return tempstring
    
        End Function
        Public Function Decrypt(ByVal stringa() As Char, ByVal key As Integer) As String
    
            Dim length As Integer = stringa.Length
            Dim tempstring() As Char = stringa
            For i As Integer = 0 To length - 1
                Dim KeyStep As Integer = key + i
                tempstring(i) = Chr(Asc(stringa(i)) - KeyStep)
            Next
    
            Return tempstring
    
        End Function
    Last edited by Sixx93; 07-22-2013 at 03:13 AM.

  5. #5
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold
    Quote Originally Posted by Sixx93 View Post
    ...
    Dim tempstring() As Char = stringa

    Is done to get the same length as stringa



    tempstring(i) = stringa(i).ToString + KeyStep.ToString

    How can it changes the original?! The equation is meant to modify the tempstring.
    Value types vs Reference Types

    I'm not going to even try to explain it...I hope you understand pointers, it's basically the same thing.
    Arrays, in .net, are actually a reference type (as are all object of a class type), so when you set one = to another, you're just changing where the variable name points to. Sorry I can't explain better, you should probably read a proper tut. about it.

    -------------------------------------------------------------------------------------------------------
    Public Function Crypt(ByVal stringa() As Char, ByVal key As Integer) As String

    Dim length As Integer = stringa.Length
    Dim tempstring() As Char = stringa '// still assigning a reference

    For i As Integer = 0 To length - 1
    Dim KeyStep As Integer = key + i
    tempstring(i) = Chr(Asc(stringa(i)) + KeyStep)
    Next

    Return tempstring '// Place a breakpoint on this line (click to the left of it, a red ball will appear).
    '// to verify. Hover mouse over variable name to see it's current value.


    End Function

    ---------- Post added at 07:59 PM ---------- Previous post was at 07:55 PM ----------

    Also called "value semantics" vs "reference semantics" . Arrays are a reference. Debug and check if it's still changing the original. A msgbox() would do.

    --Dim tempstring() As Char = stringa

    Dim tempstring(stringa.Length -1) As Char
    Array.Copy(***) maybe?
    Last edited by abuckau907; 07-22-2013 at 07:23 PM.
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

  6. #6
    Sixx93's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    673
    Reputation
    21
    Thanks
    250
    My Mood
    Cool
    Quote Originally Posted by abuckau907 View Post
    Value types vs Reference Types

    I'm not going to even try to explain it...I hope you understand pointers, it's basically the same thing.
    Arrays, in .net, are actually a reference type (as are all object of a class type), so when you set one = to another, you're just changing where the variable name points to. Sorry I can't explain better, you should probably read a proper tut. about it.

    -------------------------------------------------------------------------------------------------------
    Public Function Crypt(ByVal stringa() As Char, ByVal key As Integer) As String

    Dim length As Integer = stringa.Length
    Dim tempstring() As Char = stringa '// still assigning a reference

    For i As Integer = 0 To length - 1
    Dim KeyStep As Integer = key + i
    tempstring(i) = Chr(Asc(stringa(i)) + KeyStep)
    Next

    Return tempstring '// Place a breakpoint on this line (click to the left of it, a red ball will appear).
    '// to verify. Hover mouse over variable name to see it's current value.


    End Function

    ---------- Post added at 07:59 PM ---------- Previous post was at 07:55 PM ----------

    Also called "value semantics" vs "reference semantics" . Arrays are a reference. Debug and check if it's still changing the original. A msgbox() would do.

    --Dim tempstring() As Char = stringa

    Dim tempstring(stringa.Length -1) As Char
    Array.Copy(***) maybe?
    Yeah, I understand what you are talking about... It's like C++ pointers... When you put them = to something you change the pointed memory not the real variable.


    I think that the reason why I don't see this problem is that I pass at the function a TextBox.Text as Stringa(), so the function doesn't change the proper text of the textbox

  7. #7
    wut12345's Avatar
    Join Date
    Oct 2012
    Gender
    male
    Posts
    294
    Reputation
    16
    Thanks
    1,453
    1+3+3=7 1337

  8. #8
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    How in the name of fuck does it take so long to figure this out:

    Code:
    Public Shared Function Crypt(ByVal raw As String, ByVal key As Integer) As String
        Dim sb As New StringBuilder(raw.Length + 1)
        For i As Integer = 0 To raw.Length - 1
            sb.Append(Convert.ToChar(Convert.ToInt32(raw(i)) + (key + i)))
        Next
        Return sb.ToString()
    End Function
    
    Private Function Decrypt(ByVal crypted As String, ByVal key As Integer) As String
        Dim sb As New StringBuilder(crypted.Length + 1)
        For i As Integer = 0 To crypted.Length - 1
            sb.Append(Convert.ToChar(Convert.ToInt32(crypted(i)) - (key + i)))
        Next
        Return sb.ToString()
    End Function

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  9. The Following User Says Thank You to Jason For This Useful Post:

    [MPGH]master131 (07-24-2013)

  10. #9
    Sixx93's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    673
    Reputation
    21
    Thanks
    250
    My Mood
    Cool
    Quote Originally Posted by Jason View Post
    How in the name of fuck does it take so long to figure this out:

    Code:
    Public Shared Function Crypt(ByVal raw As String, ByVal key As Integer) As String
        Dim sb As New StringBuilder(raw.Length + 1)
        For i As Integer = 0 To raw.Length - 1
            sb.Append(Convert.ToChar(Convert.ToInt32(raw(i)) + (key + i)))
        Next
        Return sb.ToString()
    End Function
    
    Private Function Decrypt(ByVal crypted As String, ByVal key As Integer) As String
        Dim sb As New StringBuilder(crypted.Length + 1)
        For i As Integer = 0 To crypted.Length - 1
            sb.Append(Convert.ToChar(Convert.ToInt32(crypted(i)) - (key + i)))
        Next
        Return sb.ToString()
    End Function
    the stringbuilder gave me some errors. Anyway this topic is solved.

    /request close

  11. #10
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Sixx93 View Post
    the stringbuilder gave me some errors. Anyway this topic is solved.

    /request close
    You'll need to reference the System.Text namespace, obviously.

    Code:
    Imports System.Text

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  12. #11
    abuckau907's Avatar
    Join Date
    Dec 2012
    Gender
    male
    Location
    other side of the wire
    Posts
    1,342
    Reputation
    162
    Thanks
    239
    My Mood
    Cold
    Quote Originally Posted by Sixx93 View Post
    the stringbuilder gave me some errors. Anyway this topic is solved.

    /request close
    Generally you can google any className + ".NET" and first result will tell you the Namspace it's in.
    Replace Dim sb As New StringBuilder(crypted.Length + 1) with Dim sb As New System.Text.StringBuilder(crypted.Length + 1), same with the other occurrence.
    'Some things that can be counted, don't matter. And some things that matter, can't be counted' - A.E.
    --
     

    My posts have some inaccuracies/are wrong/wrong keyword(s) used.
    They're (maybe) pretty close, and I hope they helped you, not created confusion. Take with grain of salt.

    -if you give rep, please leave a comment, else it means less.

  13. #12
    Sixx93's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    673
    Reputation
    21
    Thanks
    250
    My Mood
    Cool
    Quote Originally Posted by Jason View Post


    You'll need to reference the System.Text namespace, obviously.

    Code:
    Imports System.Text
    of course, but when i declared the string as stringbuilder it said me that the class didn't have that member

Similar Threads

  1. [Solved] Name Change Code
    By FR4GX in forum Alliance of Valiant Arms (AVA) Help
    Replies: 1
    Last Post: 03-17-2013, 06:15 AM
  2. [Preview] Changed Coding With Old dBased Script
    By NaniCyunk in forum Mission Against Terror Discussions
    Replies: 46
    Last Post: 01-02-2012, 05:44 AM
  3. [HELP] Changing swap code
    By Golden. in forum Visual Basic Programming
    Replies: 0
    Last Post: 06-29-2010, 05:44 AM
  4. How to Edit a files source Code to change so that it is less detectable
    By zakodia in forum Call of Duty Modern Warfare 2 Help
    Replies: 5
    Last Post: 02-19-2010, 07:24 PM
  5. Code for changing your ip?
    By deathninjak0 in forum Visual Basic Programming
    Replies: 7
    Last Post: 11-26-2009, 01:15 PM