Thread: Decrypted Message, but not really.

  1. #1
    Registered User KAUFMANN's Avatar
    Join Date
    Jan 2011
    Location
    Coimbra, Portugal
    Posts
    31

    Exclamation Decrypted Message, but not really.

    Well, I have this message to decrypte the following way: each letter should be moved two rows ahead, so if we have ABC, the output should be CDE.

    I've made the code, seems fine to me but doesn't work and I think there's a bug in my reasoning. Could you take a look?


    Code:
    #include <stdio.h>
    #include <string.h>
    int main(void){
    
    	char msg[]="g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj";
    
    	int i,k,len;
    	len=strlen(msg);
    	for(i=0;i<len;i++){
    		printf("%c",msg[i+2]);}
    	printf("\n");
    	return 0;
    }
    ˙uıɐƃɐ ʎɐq-ǝ ɯoɹɟ pɹoqʎǝʞ ɹǝɥʇouɐ ƃuıʎnq ʇou ɯı

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If it is encrypted, shouldn't you be subtracting 2 to decrypt it? Also, it should be:
    Code:
    printf("%c", msg[ i ] -2 );
    Becuase you want to subtract from the letter, not from the spot in the array (or add I guess).


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

  3. #3
    Registered User KAUFMANN's Avatar
    Join Date
    Jan 2011
    Location
    Coimbra, Portugal
    Posts
    31
    Quote Originally Posted by quzah View Post
    If it is encrypted, shouldn't you be subtracting 2 to decrypt it? Also, it should be:
    Code:
    printf("%c", msg[ i ] -2 );
    Becuase you want to subtract from the letter, not from the spot in the array (or add I guess).


    Quzah.
    OMG You're a freakin' genius! It totally worked Thank you so much. And to think that it was only a matter of puttin' there [i]+2 instead of [i+2]
    I didn't know it made that much of a difference!

    Thank you
    ˙uıɐƃɐ ʎɐq-ǝ ɯoɹɟ pɹoqʎǝʞ ɹǝɥʇouɐ ƃuıʎnq ʇou ɯı

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    x = array[ from_here + 2 ]; /* put the value of array spot 'from_here + 2' into x */
    x = array[ from_here ] + 2; /* get the value of array spot 'from_here', then add 2 to that, and put it into x */
    That's the difference between the two.


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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message Box in C++
    By Yuri in forum C++ Programming
    Replies: 11
    Last Post: 08-19-2005, 11:43 AM
  2. i got the message
    By sanju in forum C Programming
    Replies: 2
    Last Post: 12-11-2002, 12:53 AM
  3. Message
    By Magos in forum Windows Programming
    Replies: 1
    Last Post: 08-15-2002, 06:12 PM
  4. Replies: 4
    Last Post: 01-06-2002, 06:22 PM
  5. what WM_* message?
    By canine in forum Windows Programming
    Replies: 2
    Last Post: 11-26-2001, 08:54 AM