Thread: Linux Encryption

  1. #1
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533

    Cool Linux Encryption

    Code:
    /*
     * Encrypt
     * encrypt.c
     * compile on linux; use:
     * gcc -o encrypt -lcrypt encrypt.c
     * (C) Lucas Campbell 2001-2002
     */
    
    
    #include <stdio.h>
    int main(int argc, char* argv[])
    {
    	if(argv[1] != NULL) {
    		printf("%s is encrypted using md5 as:\n",argv[1]);
    		printf("%s\n",crypt(argv[1],"$1$kL10as");
    	}
    	else {
    		ptintf("Need to add the string to be encrypted\n");
    		printf("Example: encrypt [text here]\n");
    	}
    	return 0;
    }
    
    // See top for details
    now I am wondering how I can make a random salt that is 9 characters long but the first 3 are "$1$" because that initiates the md5 encryption algorithm.
    Any help will be appreciated
    The encryption program is mine and feel free to use it and distribute it as long as it contains the above information about compilation, copyright and the author.
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  2. #2
    Unregistered
    Guest
    Good thing you have that copyright notice there. You never know when some unscrupulous hacker is going to steal your code and make millions.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > now I am wondering how I can make a random salt that is 9
    > characters long but

    Here's a thought!

    srand( time( 0 ) );
    sprintf( buf "$s$%06d", rand()%1000000 );

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    Thanks, but that didn't really work.


    What I want to do is place $1$letter in an array of nine
    like:
    Code:
    [$][1][$][r][r][r][r][r][r]
    where each r is replaced with a random character
    problem is assigning more than one random integer!
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Yawn.

    #define R ((rand()%127)+1)
    sprinf( buf, "$s$%c%c%c%c%c%c",R,R,R,R,R,R );


    Or, if they have to be printable character:
    int R(void){int c=-1; while(!isprint(c))c=rand()%256;return c;}

    sprinf( buf, "$s$%c%c%c%c%c%c",R(),R(),R(),R(),R(),R() );

    Wheee...


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wireless Network Linux & C Testbed
    By james457 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-11-2009, 11:03 AM
  2. Dabbling with Linux.
    By Hunter2 in forum Tech Board
    Replies: 21
    Last Post: 04-21-2005, 04:17 PM
  3. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM
  4. Linux Encryption
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 04-22-2002, 05:19 AM