Thread: Help with my encryption program

  1. #1
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36

    Help with my encryption program

    Hey can someone help out here so it can encrypt and decrypt, i've been trying to figure it for a while and I can encrypt but I can decrypt, help would be appreciated. Thanks

    CODE::

    cout<<"Enter something you want to encrypt: "<<endl;
    cin.get(user, 256);
    cin.ignore(80, '\n');
    string_length=strlen(user);

    do
    {
    user[x];
    l++; x++;
    }

    while(x!=string_length);

    cout<<endl;
    cout<<"Encrypted: "<<endl;
    cout<<endl;
    cout<<user<<endl;
    cout<<endl;
    cout<<"Press any key to continue"<<endl;
    int wait= getch();

    clrscr();

    cout<<"Would you like to decrypt it? 1 = yes / 0 = no"<<endl;
    cin >>user_choice;

    if (user_choice==1)
    {
    x=0; l=33;
    cout<<"Test"<<endl;
    do
    {
    user[x]=l;
    l--; x++;
    }

    while(x!=string_length);

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    363
    do
    {
    user[x];
    l++; x++;
    }
    I don't get it. How does that encrypt anything?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Code:
    do { 
       user[x]; 
       l++; x++; 
    }  while(x!=string_length);
    This doesn't do anything to user[x] - sure it reads it, but that's all.

    A most trivial encryption would be
    Code:
    do { 
       user[x]++; 
       x++; 
    }  while(x!=string_length);
    The decode for this would be
    Code:
    do { 
       user[x]--; 
       x++; 
    }  while(x!=string_length);

  4. #4
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36
    THanks, that worked

  5. #5
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    Have two strings: a user plaintext string and a key string:

    Code:
    char user [31];   // 30 chars.
    char key [31];
    
    int userLength;
    int keyLength;
    int currentKeyByte = 0;
    
    cout << "Enter string: ";
    cin >> user;
    
    cout << "Enter key: ";
    cin >> key;
    
    userLength = strlen (user);
    keyLength = strlen (key);
    
    for (i = 0; i < userLength; i++)
    {
       user [i] ^= key [currentKeyByte];
       currentKeyByte++;
    
       currentKeyByte %= keyLength;
    }
    or something.

  6. #6
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36

    Exclamation

    Salem:

    do {
    user[x]++;
    x++;
    } while(x!=string_length);


    This works but how can I make it so it doesnt just increase the decimal of the ASCII by 1, I want to make it, for example, double and then divide or something to make it a complicated encryption.

    Thanks

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    10
    well
    you can do

    user[x] += 2 to add 2 but that is no very strong encryption, I suggest you use a key and 'mix up' the bits (^=) like samGwilliam already said.

  8. #8
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    is the %= operator equal to a=a%b

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > This works but how can I make it so it doesnt just increase the decimal of the ASCII by 1

    In general, you have
    &nbsp;&nbsp;&nbsp;&nbsp;user[x] = encrypt(user[x]);

    You can make encrypt anything you want, the only restriction is that it is a reversible process (the reverse is decrypt).

    So adding 1 has an obvious inverse which is subtract 1

    The rest is down to your imagination, and creating a pair of functions called encrypt() and decrypt() which mirror one another

  10. #10
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    I made a file encryption program. The encrypt and decrypt functions are referenced by a pointer. The address of this is decided before the loop so as to avoid an if statement every iteration, just one outside it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Encryption Program (help me please)
    By Arkanos in forum Windows Programming
    Replies: 7
    Last Post: 10-30-2005, 08:01 PM
  2. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  3. Basic encryption program???
    By Finchie_88 in forum C++ Programming
    Replies: 14
    Last Post: 09-10-2004, 09:01 AM
  4. Replies: 2
    Last Post: 05-10-2002, 04:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM