Thread: I do not do a lot of programing but ...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    1

    Question I do not do a lot of programing but ...

    Would really love some help on getting this working.

    I was given the decrypt function and was trying to build the shell. I really don't remember my pointers and references, but think it is close...

    Please help! - Thanks!

    Code:
    #include <stdio.h>
    
    void decrypt();
    
    int main() {
    char in[255] = "NpfTvZKQKlM8Jh19/vI";
    
    decrypt(in);
    
    }
    
    int index(char *x) {
       char encIndex[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    
    // Not sure how to reference the array, but I believe I need to take in a char and return
    // an int.
    
    return 0;
    }
    void decrypt (char *in)
    {
        char first, second, third, fourth;
        int lf_count = 0,
            i        = 0;
        int byte_count = strlen(in);
        while (byte_count > 0)
        {
            first  = index(&in[i]);
            second = index(&in[i + 1]);
            third  = index(&in[i + 2]);
            fourth = index(&in[i + 3]);
    
            if (byte_count > 2)
                first = (first << 2) | (second >> 4);
            else
                first = (first << 2);
    
            printf("%c", first);
    
            if (byte_count > 2)
            {
                if (byte_count > 3)
                    second = (second << 4) | (third >> 2);
                else
                    second = (second << 4);
            }
    
            printf("%c", second);
    
            if (byte_count > 3)
            {
                third = (third << 6) | fourth;
                printf("%c", third);
            }
    
            i += 4;
            byte_count -= 4;
            lf_count++;
        }
    }
    Last edited by Dave_Sinkula; 10-06-2006 at 06:10 PM. Reason: Added [code][/code] tags -- learn to use them yourself.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. studying c++ programing ... concern
    By azsquall in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-03-2008, 04:30 PM
  2. Human brain and programing
    By avgprogamerjoe in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 08-27-2007, 04:48 PM
  3. using fopen getting a lot of warnings
    By netiad in forum C Programming
    Replies: 1
    Last Post: 04-28-2007, 08:44 PM
  4. programing
    By NiVaG in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-03-2004, 09:19 AM