?
Solved

Can someone convert this to Visual Basic for me?

Posted on 2006-03-26
21
Medium Priority
?
372 Views
Last Modified: 2013-11-25
Can somebody convert this to Visual Basic 6.0?

http://aluigi.altervista.org/papers/ventrilo_algo.h

I tried to do it myself but there are minor things that I don't know how to do in C++ that I can't figure out anywhere.  It doesn't look like it would be very hard.

Thanks in advance.
0
Comment
Question by:learning_t0_pr0gram
  • 12
  • 8
21 Comments
 
LVL 15

Expert Comment

by:mish33
ID: 16294709
link is broken
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 16297120
It works fine for me?  Here's the coding though.  I just thought it would be easier to read with a direct link.

#include <string.h>



typedef struct {
    unsigned char   key[256];
    unsigned int    pos;
    unsigned int    size;
} ventrilo_key_ctx;



int ventrilo_read_keys(ventrilo_key_ctx *client, ventrilo_key_ctx *server, unsigned char *data, int size) {
    ventrilo_key_ctx    *tmp;
    unsigned char       *p,
                        *del = NULL;

    for(p = data; size && *p; size--, p++) {
        if(del) continue;

        if(*p == ',') {         // old versions
            del = p;
        } else if(*p == '|') {  // version 2.3
            tmp    = server;    // exchange
            server = client;
            client = tmp;
            del = p;
        }
    }

    if(!del) return(-1);

    client->size = p - (del + 1);
    server->size = del - data;

    if((client->size > 256) || (server->size > 256)) {
         return(-1);
    }

    client->pos  = 0;
    memcpy(client->key, del + 1, client->size);
    server->pos  = 0;
    memcpy(server->key, data,    server->size);

    return(0);
}



void ventrilo_first_dec(unsigned char *data, int size) {
    const static unsigned char  first[] = "\xAA\x55\x22\xCC\x69\x7C\x38\x91\x88\xF5\xE1";
    int     i;

    for(i = 0; i < size; i++) {
        *data -= first[i % 11] + (i % 27);
        data++;
    }
}



void ventrilo_first_enc(unsigned char *data, int size) {
    const static unsigned char  first[] = "\xAA\x55\x22\xCC\x69\x7C\x38\x91\x88\xF5\xE1";
    int     i;

    for(i = 0; i < size; i++) {
        *data += first[i % 11] + (i % 27);
        data++;
    }
}



void ventrilo_dec(ventrilo_key_ctx *ctx, unsigned char *data, int size) {
    int     i;

    for(i = 0; i < size; i++) {
        *data -= ctx->key[ctx->pos] + (i % 45);
        data++;
        ctx->pos++;
        if(ctx->pos == ctx->size) ctx->pos = 0;
    }    
}



void ventrilo_enc(ventrilo_key_ctx *ctx, unsigned char *data, int size) {
    int     i;

    for(i = 0; i < size; i++) {
        *data += ctx->key[ctx->pos] + (i % 45);
        data++;
        ctx->pos++;
        if(ctx->pos == ctx->size) ctx->pos = 0;
    }
}
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16298431
>> I tried to do it myself but there are minor things that I don't know how to do in C++
What are those things?
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 16298517
Umm... well I only know the basics of c++, but I kind of understand everything in there.  What I don't get are things like:

ventrilo_key_ctx *ctx, unsigned char *data

What does the * do to those variables?  What's the difference if you take it off?
--------------
first[i % 11] + (i % 27);

What does the % do?
--------------
for(p = data; size && *p; size--, p++)

size && *p, what does the && do in a position like that?  I know what && means in an if statement, but what about in the for statement like that? Also, the * there confuses me too, but if that's just like the variable declaration then...

That's about all I don't understand, by the looks of it.
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 16299004
I should also add that I don't get what some of the data types do compared to visual basic.  For instance, take that first function, ventrilo_read_keys.  del = p;  What is del storing?  A character?  Then why is it doing this further down: client->size = p - (del + 1);  If it's a character?  This type of stuff confuses me.  I just thought that someone who knew both VB and C++ could convert it in no time.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16299648
>> ventrilo_key_ctx *ctx, unsigned char *data
This is a pointer type.

>> What does the % do?
% is a mod operator. Similar to mathematical mod for integer division.
Ex:  5/2 = 2, 5%2 = 1
0
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 1500 total points
ID: 16299672
>> size && *p, what does the && do in a position like that
It is comditional and operator
Ex: 1 && 1 = 1
     0 && 1 = 0
     0 && 0 = 0

>> *p
It means value of p.
Example:
int* p; // p is a pointer variable
int x = 10; // x is an integer variable having value 10
p = &x; // p is pointing to x.

*p // Value of the variable in which it is pointing, now it is 10.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16299680
>> ventrilo_key_ctx *ctx, unsigned char *data
As I said before pointer variables can pointer to nowhere. In that case your program crashes if you use that variable.

Ex:
int* p; // p is a pointer variable
*p = 10; // p is pointing to nothing. PROGRAM CRASH.
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 16307305
So if *p is pointing to variable x, if x changes, p changes also?  Is that what the pointer variable is?  Does this mean that the for loop:

for(p = data; size && *p; size--, p++) {

will keep on looping until size OR data (p is pointing to data, right?) is empty?  Since size moves down once every iteration, it would loop a max amount of 'size'.  That's what I make of it.

But what happens when you point a pointer to a pointer?  It's pointing del at p, both are pointers.  Does this mean that when data changes, p changes, and then del changes?  If so why not just point del to data?

Am I right when I say the % returns the remainder?  6 % 2 would return 0?  If so then I understand that.

I'm still a little confused about how the different variable times are working.  I don't have much experience in c++, so please forgive me if i'm being stupid here.

In the for loop in that first function, when it does 'p = data', is it posible for an 'unsigned char' to hold more than one character?  Because I am pretty sure you're supposed to pass more than one character into it, otherwise I don't see the point of the for loop.  Plus p++ is in the third parameter of the for loop.  If p is a pointer, when you raise it by one, does it raise the variable it's pointing to?

I understand everything I asked in my previous posts now except the data part which I just asked again.  I think i'm most confused on that for loop because I don't get what is going on.  If you understand what is going on, if you explained it I would probably understand everything I asked so far.  It looks like everything else I could convert to VB easily.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16307381
>> keep on looping until size OR data (p is pointing to data, right?) is empty?
You are right
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16307400
>> But what happens when you point a pointer to a pointer?
Let me modify the language little bit.
"del is pointing to the value where p is pointing"
The thing that you are talking about is something different.

Ex:
int *p;
int **del; // See the difference in syntax
int x = 10;
p = &x;
del = &p; // Now del is pointing to a pointer.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16307421
>> Does this mean that when data changes, p changes, and then del changes?  If so why not just point del to data?
Yes, the data will change, but not the complete data.

Exmaple:
char p[] = "ABCDE";
char* ptr = p;
ptr = ptr + 2; // Now ptr is pointing to 'C'.
*p = 'Z'; // Will only change that value. String will  be "ABZDE".
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16307424
>> Am I right when I say the % returns the remainder?  6 % 2 would return 0?  If so then I understand that.
Yes you are right.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16307467
>> unsigned char *data;
When you are passing this that means you are passing a char string.
In C or C++ string comprises of n number of charaters terminated by NULL (which is 0).

Example:
unsigned char *data = "ABCDE",
data[0] = 'A';
data[1] = 'B'
data[2] = 'C'
data[3] = 'D'
data[4] = 'E'
data[5] = '\0' // Or 0, Or NULL, all are same.

length of string = 5, Last NULL will not be counted.

So, now using pointer you can iterate all the charaters in the string.

unsigned char *ptr = data;
unsigned char c; // It is a single charater
for (; *ptr ;) // *ptr will be 0 when it encounterd the terminating charater, as I said it is NULL (which is 0)
{
   c = *ptr;
}

Now don't get confused will NULL and 0. As I said NULL, 0, and '\0' are same.
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 16308643
Ok, I get everything you said, but i'm still confused about a bit more.  I converted the first function 100% and it works (I think).  But I moved onto the next and i'm a little confused about it:

void ventrilo_first_dec(unsigned char *data, int size) {
    const static unsigned char  first[] = "\xAA\x55\x22\xCC\x69\x7C\x38\x91\x88\xF5\xE1";
    int     i;

    for(i = 0; i < size; i++) {
        *data -= first[i % 11] + (i % 27);
        data++;
    }
}

I don't get what is happening.  I wrote up a little test to see what was going on so I could convert it, but all that seemed to happen was it removed the first character off of data each iteration.  Here's the test script I made

    int i;
    const static unsigned char  first[] = "\xAA\x55\x22\xCC\x69\x7C\x38\x91\x88\xF5\xE1";
    unsigned char *data = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";

    for(i = 0; i < 52; i++) {
        cout << "BEFORE: " << data << endl;
        *data -= first[i % 11] + (i % 27);
        data++;
        cout << "AFTER: " << data << endl;
    }

It only removes the first character off of data each time and I was wondering what the point of it was.  Or if my test script is somehow wrong.  I knew I would run into these problems while converting which is why I was hoping for someone else to do it.  You need to understand every bit that is happening in order to convert it, and each time I get confused I can't go on.  But if you explain each problem I have I will eventually get it done.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16308846
Little bit of modification it required in this case

int i;
const static unsigned char  first[] = "\xAA\x55\x22\xCC\x69\x7C\x38\x91\x88\xF5\xE1";
char data[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *pData = data;

cout << "BEFORE: " << data << endl;
for(i = 0; i < strlen(data); i++) {
      *data -= first[i % 11] + (i % 27);
      pData++;
}
cout << "AFTER: " << data << endl;
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 16309148
All that does is add 1 character to the end of data.  The other one did the same thing except it was removing it right after.  So could you look at that ventrilo_first_dec and tell me exactly what you think it's supposed to do?
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 16309181
I meant to the beginning of data, not the end.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16309562
I made this function little bit simpler for you

void ventrilo_first_dec(unsigned char data[], int size) {
    const static unsigned char  first[] = "\xAA\x55\x22\xCC\x69\x7C\x38\x91\x88\xF5\xE1";
    int     i;
    for(i = 0; i < size; i++) {
        data[i] -= first[i % 11] + (i % 27);
    }
}
0
 
LVL 4

Author Comment

by:learning_t0_pr0gram
ID: 16316167
And that does the same thing as the previous one?  And is it just subtracting ASCII values?  It looks to me like it's shifting decimal places DOWN in the amount of (first[i % 11] + (i % 27)).  If this does the same thing, I think I can do it now.  I am just wondering why this new one you wrote returns different characters than the one in my 2nd comment.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16317518
All the best
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question