Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (0)

Powered by Vanilla. Made with Bootstrap.
Any got a solution for this programming challenge ?
  • mandi
    Posts: 207
    hi guys,
    here is challenge i got from my friend,i just want to know there is a solution available for this task,

    when i enter a number it should display it's equivalent binary number like for 2 = 0010 3=0011,
    but the important restriction is "IT SHOULD NOT USE/INVOKE MULTIPLICATION OR DIVISION OF ANY FORM" inside the computer.

    is there a solution possible ?

    if any one has one please post here...

  • absynth
    Posts: 8
    Wrote a quick/dirty C program to illustrate a solution. Uses subtraction and logical AND operations. It converts hex number string to binary string.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    void shell_prompt(void)
    {
        char buf[1024];

        printf("Type exit to quit, valid string chars 0-9, A-F, a-f.\n");
        while(1)
        {
            printf(">");
            gets(buf);
            if (strcmp(buf, "exit") == 0) break;
            else string_convert(buf);
        }
    }

    int string_convert(char *num)
    {
        char *ret;
        int i;

        ret = (char *)malloc(sizeof(char)*strlen(num));

        /*
        ASCII input -- 0 - 9: 48 - 57; A - F: 65 - 70; a - f: 97 - 102
        */   
        for (i = 0; i < strlen(num); i++)
        {
            if ((int)num[i] > 47 && (int)num[i] < 58)
                ret[i] = num[i] - 48;
            else if ((int)num[i] > 64 && (int)num[i] < 71)
                ret[i] = num[i] - 55;
            else if ((int)num[i] > 96 && (int)num[i] < 103)
                ret[i] = num[i] - 87;
            else
            {
                printf("Invalid character string. Valid characters 0-9, a-f, A-F.\n");
                return 1;
            }

            if (ret[i] & 0x8) printf("1"); else printf("0");
            if (ret[i] & 0x4) printf("1"); else printf("0");
            if (ret[i] & 0x2) printf("1"); else printf("0");
            if (ret[i] & 0x1) printf("1"); else printf("0");
            printf(" ");
        }
        printf("\n");
        return 0;
    }

    int main(int argc, char **argv)
    {
        if (argc < 2)
        {
            printf("No arguments given, defaulting to prompt.\n");
            shell_prompt();
        }
        else string_convert(argv[1]);
        return 0;
    }

  • Mr. P-teoMr. P-teo
    Posts: 269
    Looks like the above code has a buffer overflow vuln, may be wrong but it appears that way.
    Skype: mrpt3o
    Twitter: MrPteo


    image
  • absynth
    Posts: 8
    ...this was only proof of concept, not designed to be secure, there probably is a buffer overflow vuln in here, but I'll leave that open for you to find out...
  • Mr. P-teoMr. P-teo
    Posts: 269
    haha was only looking through it as iv been learning buffer overflows recently.
    Skype: mrpt3o
    Twitter: MrPteo


    image
  • absynth
    Posts: 8
    "Smashing the stack for Fun and Profit" is a good place to start... ;)
  • mandi
    Posts: 207
    hi bro,thanks for the solution mate :)
  • scripter
    Posts: 6
    yes there is a b0f in there... but I think that is doesn't matter for the case , I really dont know many functions in C , but in many languages exist a way to convert with pre-maded funcions , I recommend to search about that function :) its save a lot of work