Encryption

This is a discussion on Encryption within the C++ Programming forums, part of the General Programming Boards category; I seen another post on here about encryption and I thought I would try my hand at some XOR stuff. ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    1

    Post Encryption

    I seen another post on here about encryption and I thought I would try my hand at some XOR stuff. I had it perfect but know I want to add in the chance for people to write in the txt they want to be encrypted. I had that working but afterit decrypted the txt there was still a bunch of mubly jumbly after it. So I decided I wanted to clean it up. This is what I got. The comments explain where the errors are at and what they are.

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    int main()
    {     char a[501];
          char b[502]="dmj7HaL(*EjJNuh88iNU67Jbn76n75hu767Bhg567b765mdsd4s";
          char c[501];
          int leg;
          int g=0,h=0;
          cout<<"\nPlease Input Some Text To Be Encrypted\n\n";
          cin.getline(a,502);
          strlen(a)=leg;//problem here I want "leg" to equal the length of "a" "non-lvalue in assignment error"
          while(g<leg)
          {
                  for(int x=0, x<502, x++)//parse error before")" here
                  {
                    c[x]=b[x]^a[x];
                    cout<<c[x];} //parse error before "}" here
          
          g++;
          }
          cout<<"\n\nYour Decrypted Text\n\n"; }
          while(h<leg)
          {     
               for(int x=0, x<502, x++) //parse error before ")" here
               {
                 a[x]=b[x]^c[x];
                 cout<<a[x];
                }          //parse error before "}" here
           h++;
           }     
          cout<<"\n\n";
    
    
          system("PAUSE");
          return 0;
    }         //parse error at the end of input here.   There is also a "no8"  error on line 14 of a source I don't have open call'd 

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    that should be "leg = strlen(a);" and i believe that will fix all your other errors

  3. #3
    Ted
    Ted is offline
    Registered User
    Join Date
    Aug 2001
    Posts
    52
    Good news! Your loop parse errors are syntax errors. Take a
    closer look. You also have a premature end main brace (}).
    I'll let you find it.

    hth,

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    208

    But???

    I know that they were syntax errors but I am not good enuff at reconizing them yet thats why I asked about them. I have only been programing for less the 3 weeks?

  5. #5
    Ted
    Ted is offline
    Registered User
    Join Date
    Aug 2001
    Posts
    52
    the commas in your for loops should be semicolons. Compare your code to this:
    Code:
    int main()
    {
         char a[53] = "\0";	// input
          char b[] = " JNuh88iNU67Jbn76n75hu767Bhg567b765mdsd4s";
          char c[53] = "\0";	// output
          int leg, g = 0, h = 0;
          
         cout << "\nPlease Input Some Text To Be Encrypted"
                 << endl;
    
         cin.getline( a, 52 );  
          
         leg = strlen( a );
    
         cout << endl << "Your encrypted text: ";
    
          for(int x = 0; x < leg; x++)
              c[x] = b[x] ^ a[x];           // xor a to c
    
          cout << c << endl;              // you can treat an array as a string
    
          cout << "\n\nYour Decrypted Text:  "; 
    
    
          for( x = 0; x < leg; x++ ) 
          {
              a[x] = b[x] ^ c[x];
              cout << a[x];
          }
    	 
    	  
          cout << "\n" << endl;
    
          return 0;
    }
    hth,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. help needed with edit control & encryption
    By willc0de4food in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2006, 08:21 PM
  3. abt encryption algorithm
    By purIn in forum C Programming
    Replies: 9
    Last Post: 12-22-2003, 10:16 PM
  4. What's wrong with my Stream Cipher Encryption?
    By Davros in forum C++ Programming
    Replies: 3
    Last Post: 04-18-2002, 10:51 PM
  5. File Encryption & Read/Write in Binary Mode
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 06:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21