Thread: help with encrypting plz

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    3

    help with encrypting plz

    hey, could anyone plz tell me who to encrypt like something using a user defined value with the help of an array, like if they user writes 30, then it puts that too the ascii value of the letter so it changes, and stuff like that, tried to do it, but it kind of I am sillyI am sillyI am sillyI am sillyed up when decrypting, it wouldn't decrypt if the value of the number were over a specifik height and don't know why.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    basic basic basic encryption to get you started:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    int main(void)
    {
      unsigned seed= (unsigned)time(NULL);
      int counter;
      char arr[]="Hello World";
      int length = strlen(arr);
      srand(seed);
    
      puts(arr);
      for (counter=0; counter<length; counter++)
        arr[counter]+=rand();
    
      puts(arr); /* Note this may not be a valid C string at this point */
      srand(seed);
    
      for(counter=0; counter<length; counter++)
        arr[counter]-=rand();
      puts(arr);
    
      return 0;
    }
    If you want to really get encryption you have a long road ahead of you.
    Last edited by Thantos; 03-31-2004 at 10:28 AM. Reason: Fix small problem in the code

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    72
    Quote Originally Posted by wimpman
    hey, could anyone plz tell me who to encrypt like something using a user defined value with the help of an array, like if they user writes 30, then it puts that too the ascii value of the letter so it changes, and stuff like that, tried to do it, but it kind of I am sillyI am sillyI am sillyI am sillyed up when decrypting, it wouldn't decrypt if the value of the number were over a specifik height and don't know why.
    Post what you have

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    3
    Code:
    void kryptering(int Lang)
    {
    	//char streng[81];
    	char krypt[81];
    	int kontrol;
    	int i;
    
    	printf("What do you want to encrypt?: ");
    	gets(krypt);
    
    	printf("what do you want your encryption key to be: ");
    	scanf("%d",&kontrol);
    
    	do{
    		for(i=0;i<=81;i++)
    		{	
    			krypt[i] = krypt[i] + kontrol;
    		}
    	}while(i > 255);
    }


    it's that kind of extremly simple stuff I'm looking for, then when I try to decrypt it with this code it totally messes up with certain values set as encryption key....


    Code:
    void dekryptering(Lang)
    {
    	char ikrypt[81];
    	char dkrypt[81];
    	char ckontrol[1];	
    	int dkontrol;
    	int i;
    
    	printf("what were your encryption key: ");
    	gets(ckontrol);
    	dkontrol = atoi(ckontrol);
    	
    	Read_file();
    	if(!fp)
    	{
    		return;
    	}
    
    	fgets(ikrypt,81,fp);
    	
    	Close_file();
    
    	for(i=0;i<=81;i++)
    	{
    		dkrypt[i] = ikrypt[i] - dkontrol;
    
    		if(ikrypt[i] < 0)
    		{
    			dkrypt[i] = 0;
    		}
    	}
    }
    this is not the complete code but just the one I thought would have influence on teh problem, in the read file part, I just extract te result from the encryption to a the variabel ikrypt.
    Last edited by wimpman; 03-31-2004 at 11:57 AM.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    do{
    for(i=0;i<=81;i++)
    {
    krypt[i] = krypt[i] + kontrol;
    }
    }while(i > 255);
    That do while does nothing since i will always be 82 after the first iteration
    gets(krypt);
    see the FAQ on why gets is bad
    I am sillyI am sillyI am sillyI am sillys
    no one here cares if you are silly. Stating that fact generally will turn people off
    for(i=0;i<=81;i++)
    should be
    Code:
    for(i=0;i<81;i++)
    Here is an example using the same basic path you've chosen:
    Code:
    #include <stdio.h>
    #include <string.h>
    void crypt (char *, int);
    void decrypt (char *, int);
    int main (void)
    {
      char arr[81];
      crypt(arr, 81);
      decrypt(arr, 81);
      puts(arr);
      getchar();
      return 0;
    }
    void crypt(char *arr, int length)
    {
      int i, key = 5;
      strcpy (arr, "Encrypt this");
      for(i=0; i<length; i++)
      {
    	arr[i] = arr[i] + key;
      }
    }
    void decrypt(char *arr, int length)
    {
      int i, key=5;
      for ( i=0; i<81; i++)
      {
    	arr[i] = arr[i] - key;
      }
    }

  6. #6
    Registered User
    Join Date
    Feb 2004
    Posts
    72
    Quote Originally Posted by Thantos
    no one here cares if you are silly. Stating that fact generally will turn people off
    should be
    lol. I think "I am silly" is a replacement for characters in banned words

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    3
    hehe well the I am silly part was becuase I tried to use the F word I guess which this forum didn't like :P well I'll correct it now that I've noticed it :P

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    heh, thats actually kinda funny

  9. #9
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    Yeah, cryptology is a confusing subject -- you should go to a bookstore and read a book on it (such as Applied Cryptography or Practical Cryptography) and maybe buy it.
    01011001 01101111 01110101 00100000 01110100 01101111 01101111 1101011 00100000 01110100 01101000 01101001 01110011 00100000 01101101 01110101 01100011 01101000 00100000 01110100 01101000 01101101 01100101 00100000 01110100 01101111 00100000 01110010 01100101 01100001 01100100 00100000 01011001 01101000 01101001 01110011 00111111 00100000 01000100 01100001 01101101 01101110 00100001 00000000

  10. #10
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Or you could have a look at Handbook of Applied Cryptography here. All of the chapters are available for free.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  3. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  4. plz help me fix this problem
    By Joe100 in forum C++ Programming
    Replies: 8
    Last Post: 07-13-2003, 01:25 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM