Page 1 of 5 123 ... LastLast
Results 1 to 10 of 47

Thread: C Challenge (Part 1)

  1. #1
    Join Date
    Dec 2004
    Posts
    1,181
    Rep Power
    0

    Lightbulb C Challenge (Part I)

    This is a challlenge for all the C programmers out there. If you have the time, sit an figure this one out and post your source code that effectively and efficiently solves the problem. This one is a tough one. I have no prizes to offer you but the great feeling of accomplishment you get after figuring out a difficult programming question. I will attempt the challenge myself and upload the source code soon. Good Luck Programmers!!!

    PROBLEM

    Lets say I have a database, I would need a password system to ensure the security and integrity of the database. Passwords are great, but it would be better if the password itself was encrypted by a certain algorithm which would make it difficult for an unauthorized person to decipher.
    The algorithm should:

    [1] Upgrade each character of the password to the next corresponding letter in the alphabet.

    e.g. apple would become bqqmf

    [2] Then each new character would be converted to the sixth corresponding counted character behind it, including the itself.

    e.g. bqqmf would become wllha

    [3] Then each new character would be converted to the eleventh corresponding counted character infront it, including the itself.

    e.g. wllha would become gvvrk
    Last edited by psybuck2002us; Apr 20, 2005 at 08:34 PM.

  2. #2
    Join Date
    Aug 2004
    Posts
    2,789
    Rep Power
    0

    Default

    What i'm thinking is quite simple. going to try it now
    The views expressed in the above post are not neccesarily the views of icuucme.

  3. #3
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    So basically thats equivalent to incrementing to the 6th corresponding counted character infront.

    simple........too simple

  4. #4
    Join Date
    Aug 2004
    Posts
    2,789
    Rep Power
    0

    Default

    that's what i was thinking, where's the challenge?
    The views expressed in the above post are not neccesarily the views of icuucme.

  5. #5
    Join Date
    Apr 2004
    Posts
    554
    Rep Power
    0

    Default

    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    
    void main(){
    	
      int i=0,x=0,loop=0;
      char pwd[6];
      do{
    	printf("Enter your five letter password:");
    	gets(pwd);
    	
    	for(x=0;x<5;x++){
    
            	if( (pwd[x] > 96 && pwd[x] < 123) || (pwd[x] > 64 && pwd[x]< 91)){
    			loop=1;
    			pwd[x] = tolower(pwd[x]); //converts letter to lowercase
    			
    			if(pwd[i]==122) //if the char is z
    				pwd[i]=97; //char is a
    			else pwd[i]+=1; //else increment by one 
    				
    				
    			if((pwd[i]-5) < 97) //if char is less than 5 chars away from a
    				pwd[i] = 122 - ((pwd[i]+1)-96); //calculate new value
    			else pwd[i]-=5; //else decrement by 5
    				
    				
    			if((pwd[i]+10) > 122) //if char is less than 10 chars away from z
    				pwd[i] =  97 + (10-(122 - (pwd[i]-1))); //calculate new value
    			else pwd[i]+=10; //else increment by 10
    				
    			i++;
    		}
    		else{
    			printf("Invalid character entered\n");
    			loop=0;
    			break;
    		}
    
    	}
      }while(loop==0);
    
    }
    Last edited by nigelt; Apr 21, 2005 at 02:10 AM. Reason: Added input validation and [code][/code] tags
    Nexus S - Android 2.3.3 CM7, Jame Bond kernel with BLN, ext4 & full voodoo
    Bold 9700 - OS6.0.0.448

  6. #6
    Join Date
    Jan 2005
    Posts
    3,151
    Rep Power
    0

    Default

    what the?
    How about a real challenge?

  7. #7
    Join Date
    Apr 2004
    Posts
    537
    Rep Power
    0

    Default

    Here is One,lwrite a source program that, when compiled and executed, will produce as output an exact copy of its source.

  8. #8
    Join Date
    Mar 2004
    Posts
    123
    Rep Power
    0

    Default

    Think this will do the job

    Code:
    /*
    Created By:	TJRAK			
    Title:		printcode.c
    */  
    
    #include <stdio.h>
    #include <stdlib.h>
    
    void main()
    {
     FILE *indt;
     char getdata[100]; 
    
     if ( (indt = fopen("printcode.c", "r"))==NULL)
    
     	printf("Could not open input file");
     else {
       while(!feof(indt)) {
       	fgets(getdata,100, indt);
    	puts(getdata);
          }//end while
       
    
     fclose (indt);
     
    
     }//end else not file open error
    }
    Last edited by TJRAK; Apr 21, 2005 at 03:36 PM.
    There is no wrong or right, only consequencies to action

    "It is the duty of man to make his knowledge so complete in life, so as to make it impossible for any other to take advantage of him" - Marcus Garvey

  9. #9
    Join Date
    Mar 2004
    Posts
    123
    Rep Power
    0

    Default 3N+1 Problem

    That one was too easy. Isn't the topic of this thread "C Challenge"? What say we give the 3N+1 Challenge a try. This should keep you busy for at least a day.
    There is no wrong or right, only consequencies to action

    "It is the duty of man to make his knowledge so complete in life, so as to make it impossible for any other to take advantage of him" - Marcus Garvey

  10. #10
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    Quote Originally Posted by The good guy
    Here is One,lwrite a source program that, when compiled and executed, will produce as output an exact copy of its source.
    ohh come on. r u guys trying to trick us into doing ur home work or what?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •