Thread: Encrypt/Decrypt

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    3

    Unhappy Encrypt/Decrypt

    OK, I've decided that my 2 1/2 year old will be easier to figure out than the beginings of C programming. Well, I've tried all three and attempted modification (out of guessing) and still don't reach my needed result. Once again, out of any order of numbers such as 1234(I've just pick this size in digits, could be larger if I wanted), I need to encrypt that number by adding 7 to each charater: (1 becomes 8, 2 becomes 9, 3 becomes 0 and 4 becomes 1) The last digit of the roleover is not used. Can anyone see where I'm messing up?

    #include <stdio.h>
    #include <stdlib.h>

    int main(void)
    {
    system("cls");

    int temp, int exp = 0, int encrypted = 0, int normal;
    int pow

    while(normal > 0){
    temp = normal % 10;
    temp += 7;
    temp = temp % 10;
    encrypted += temp * pow(10,exp);
    exp ++;
    normal /= 10;

    printf("Enter your name: ");
    scanf("%s", name);

    printf("Enter a number to encrypt: ");
    scanf("%f", temp);

    printf("new number is: %f%f%f%f, ");


    return EXIT_SUCCESS;
    return 0;
    }

    Now the rest of this small snippit is to decrypt the number back to the orignal number set but should be nothing but reversing the encrypting part. any ideas.....,

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Code:
    #include <stdio.h>
    
    void encrypt ( char *buff ) {
        int i;
        for ( i = 0 ; i < strlen(buff) ; i++ ) {
            char c = buff[i] - '0';
            c = ( c + 7 ) % 10;
            buff[i] = c + '0';
        }
    }
    
    int main ( ) {
        char test[] = "1234";
        encrypt( test );
        printf( "%s\n", test );
        return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    104
    Hi there!

    I suggest you learn about the base 64bit encryption... it's easy and cool :-) /and unsafe...but safer thatn Ceaser's crypting.../.
    Here is a tutorial about it:
    http://www.cpp-home.com/tutorial.php?102_1

    Also, you may want to see about the XOR encryption at:
    http://www.cpp-home.com/tutorial.php?120_1

    and about the RSA encryption at:
    http://www.cpp-home.com/tutorial.php?139_1
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. looking for simple encrypt/decrypt commands
    By sept in forum C++ Programming
    Replies: 4
    Last Post: 09-28-2007, 07:11 PM
  2. Encrypt/Decrypt files by XOR
    By amirahasanen1 in forum C++ Programming
    Replies: 27
    Last Post: 05-22-2005, 02:38 PM
  3. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  4. how to encrypt/decrypt
    By bitWise in forum C Programming
    Replies: 3
    Last Post: 10-13-2001, 01:02 PM