Hidden issues in crypto program.

This is a discussion on Hidden issues in crypto program. within the C++ Programming forums, part of the General Programming Boards category; The issues is that my Vigenere encryption program works to the point where you can encrypt things, and almost decrypt ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    65

    Hidden issues in crypto program.

    The issues is that my Vigenere encryption program works to the point where you can encrypt things, and almost decrypt things perfectly. 9/10ths of the time the decryption works but when it decrypts something with over 4 spaces it might cut up the out put. Here is the code and header file.

    Header
    Code:
    *I am going to make my own simple encryption program, cause thats what programmers do
      Name:TothEncrypt  
      Copyright: GNU Public Licence
      Author:Will Toth 
      Date Started: 29/10/07 14:02
      Description: Very Simple Encryption program 
    */
      
    #include <iostream>
    int TKeyNum=0;
    class toth
    {
          public:
                void SetNum(int keynum1){TKeyNum=keynum1;};   
                
                //Ceasar Shift Cypher. Works 100%. Is very easy to crack 
                void Tencrypt(int key1, char (&array1)[256] )
                 {                                                             
                              int x;
                              int y;
    
                              for(x=0;array1[x]!='\0';x++)
                              {
                                    for(y=0;y<256;y++)
                                    {
                                        //std::cout << (char)y << std::endl;
                                        if(array1[x]==(char)y) 
                                         // When the charater in the array is equal to the one in the loop
                                        
                                        {
                                            array1[x]=(char)(y+key1); 
                                            //  it adds x (key1) to the current character
                                            y=0;
                                            break;
                                        }
                                    }
                                }
    
    
                        
                 }
                 
                  void Tdecrypt(int key1, char (&array1)[256] )
                 {                                                             
                              int x;
                              int y;
    
                              for(x=0;array1[x]!='\0';x++)
                              {
                                    for(y=0;y<256;y++)
                                    {
                                        //std::cout << (char)y << std::endl;
                                        if(array1[x]==(char)y) 
                                         // When the charater in the array is equal to the one in the loop
                                        
                                        {
                                            array1[x]=(char)(y-key1); 
                                            //  it adds x (key1) to the current character
                                            y=0;
                                            break;
                                        }
                                    }
                                }
    
    
                        
                 }
                 
                 
                 //Vingere Cypher
    
                 void Tencrypt(char textkey[], char (&array1)[256])
                 {
                        
                        int x;
                        int y;
                        int z=0;
                        int key1;
                              
                       
                            for(x=0;array1[x]!='\0';x++)     //scans whole thing
                              {
                                    
                                     
                                        { 
                                               if(z==strlen(textkey))
                                                    {
                                                         z=0;                                                     
                                                    }
                                               key1=((int)(textkey[z])-'a');
                                               z++;
                                              
                                    
                                        }
                                                                     
                                    
                                    
                                    
                                    std::cout << key1 << std::endl; 
                                                for(y=0;y<256;y++)
                                                {
                                                    //std::cout << (char)y << std::endl;
                                                 if(array1[x]==(char)y)
                                                  {
                                                      array1[x]=(char)(y+key1);
                                                       y=0;
                                                      break;
                                                   }
                                                }
                                    
                                }
                 }
                 
                 void Tdecrypt(char textkey[], char (&array1)[256])
                 {
                        
                        int x;
                        int y;
                        int z=0;
                        int key1;
                              
                       
                            for(x=0;array1[x]!='\0';x++)     //scans whole thing
                              {                              
                                     
                                        
                                        { 
                                               if(z==strlen(textkey))
                                                    {
                                                         z=0;                                                     
                                                    }
                                               key1=((int)(textkey[z])-'a');
                                               z++;
                                              
                                    
                                        }
                                                                 
                                      
                                    
                                    
                                    
                                    std::cout << key1 << std::endl; 
                                                for(y=0;y<256;y++)
                                                {
                                                    //std::cout << (char)y << std::endl;
                                                 if(array1[x]==(char)y)
                                                  {
                                                      array1[x]=(char)(y-key1);
                                                       y=0;
                                                      break;
                                                   }
                                                }
                                    
                                }
                 }
                
                 
    };
    Main program
    Code:
    //#include <iostream>
    #include "tothencrypt.h"
    #include <iostream>
    int main()
    {
        //char dog[4];
        toth newtoth;
        char dog[256] = "the desert fox got foxed";
        
        char keyword[256] = "YouCant gef Daf";
        char cat[256] = "Adam Hendrickson Is A crazy Pshyco ..........";
        /*int i = strlen(keyword);
        cout << "i = : "<< i << endl; */
        //newtoth.Tencrypt(3,cat);
        newtoth.Tencrypt(keyword,dog);   //should be Forltuulod
        std::cout << "dog :" << dog << "\tShould be: Forltuulod" << std::endl 
            << "Cat :" << cat << "\tShould be: Fdoliruqld" << std::endl;
        newtoth.Tdecrypt(keyword,dog);
        std::cout << dog;    
        getchar();
    }
    You rant and rave about it, but at the end of the day, it doesn't matter if people use it as long as you don't see.
    People are free to read the arguments, but if the only way for you to discover gravity is by jumping off a cliff, then that is what you're going to have to experience for yourself.
    Eventually, this "fast and loose" approach of yours will bite you one too many times, then you'll figure out the correct way to do things. - Salem

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    My bro will fixed it. Thanks for your time.
    You rant and rave about it, but at the end of the day, it doesn't matter if people use it as long as you don't see.
    People are free to read the arguments, but if the only way for you to discover gravity is by jumping off a cliff, then that is what you're going to have to experience for yourself.
    Eventually, this "fast and loose" approach of yours will bite you one too many times, then you'll figure out the correct way to do things. - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 10:49 PM
  2. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  3. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  4. Replies: 3
    Last Post: 01-14-2003, 10:34 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM

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