Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 10-16-09   #1 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,449

Rep: 200 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 173
Folding Team Rank: 292
Trader Rating: 24
Default Complete c++ decode program

Code:
#include <iostream>
#include <iomanip>
#include <ctype.h>
using namespace std;
char revCaesar(char);
char convPunct(char);
char convDigit(char);
char convRest (char);
int main()
{
    char ch;
    cin >> ch;
    while (ch)
    {
          if (isalpha(ch))
                {
                 revCaesar(ch);
                }
          else if (ispunct(ch))
                {
                 convPunct(ch);
                }
          else if (isdigit(ch))
                {
                 convDigit(ch);
                }
          else 
                 convRest(ch);
                
                cout<<ch;
                cin>>ch;
    }
system ("pause");
return 0;
}
//Function 1 - undoes the Caesar Cipher
char revCaesar(char ch)
{
     if(isupper(ch))
            
           {
            if(ch <= 'D' and ch >= 'Z')
                  {
                   int ch;
                   ch = ch - 3;
                   return ch;
                  }
            else
                
                switch(ch)
                            {
                            case 'A':
                            ch = 'X';
                            break;
                            case 'B':
                            ch = 'Y';
                            break;
                            case 'C':
                            ch = 'Z';
                            break;
                            }
            return ch;
           }
     else
           {
            if(ch <= 'd' or ch >= 'z')
                  {
                   int ch;
                   ch = ch - 3;
                   return ch;
                  }
            else
                  {
                  char s;
                  switch(ch)
                            {
                            case 'a':
                            s = 'x';
                            break;
                            case 'b':
                            s = 'y';
                            break;
                            case 'c':
                            s = 'z';
                            break;
                            }
                  }          
            return ch;
}
}            

//Function 2 

char convPunct(char ch)
{
char s;
switch(ch)
{
case '0':
s = ',';
break;
case '1':
s = '.';
break;
case '2':
s = '$';
break;
case '3':
s = '&';
break;
case '4':
s = '%';
break;
case '5':
s = '*';
break;
case '6':
s = '(';
break;
case '7':
s = ')';
break;
case '8':
s = '?';
break;
case '9':
s = '!';
break;
}
}
//Function 3

char convDigit(char ch)
{
switch(ch)
{
case '!':
ch = '0';
break;
case ',':
ch = '1';
break;
case ')':
ch = '2';
break;
case '(':
ch = '3';
break;
case '?':
ch = '4';
break;
case '-':
ch = '5';
break;
case '&':
ch = '6';
break;
case '$':
ch = '7';
break;
case '.':
ch = '8';
break;
case '+':
ch = '9';
break;
}
}

//Function 4

char convRest(char ch)
{
if( int ch = 22)
{
    ch = ' ';
    return ch;
}

else if( int ch = 21)
{
     ch = '"\n"';
     return ch;
}

else
    return ch;
}
Much thanks go to spotswood for helping me create the complete caesar cipher. Now, I've created my whole program, designed to decode a specific message . However, it compiles just fine, but when data is inputted it just returns the exact same data as was entered (aka I enter 'c' it returns 'c' instead of 'z'). Does anybody know why?
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions
tofunater is online now I fold for Overclock.net   Reply With Quote
Old 10-16-09   #2 (permalink)
Overclocker
 
B-80's Avatar
 
intel nvidia

Join Date: Oct 2006
Location: Levittown,PA / Penn State
Posts: 1,925

Rep: 86 B-80 is acknowledged by some
Unique Rep: 76
Trader Rating: 0
Default

Quote:
Originally Posted by tofunater View Post
Code:
#include <iostream>
#include <iomanip>
#include <ctype.h>
using namespace std;
char revCaesar(char);
char convPunct(char);
char convDigit(char);
char convRest (char);
int main()
{
    char ch;
    cin >> ch;
    while (ch)
    {
          if (isalpha(ch))
                {
                 revCaesar(ch);
                }
          else if (ispunct(ch))
                {
                 convPunct(ch);
                }
          else if (isdigit(ch))
                {
                 convDigit(ch);
                }
          else 
                 convRest(ch);
                
                cout<<ch;
                cin>>ch;
    }
system ("pause");
return 0;
}
//Function 1 - undoes the Caesar Cipher
char revCaesar(char ch)
{
     if(isupper(ch))
            
           {
            if(ch <= 'D' and ch >= 'Z')
                  {
                   int ch;
                   ch = ch - 3;
                   return ch;
                  }
            else
                
                switch(ch)
                            {
                            case 'A':
                            ch = 'X';
                            break;
                            case 'B':
                            ch = 'Y';
                            break;
                            case 'C':
                            ch = 'Z';
                            break;
                            }
            return ch;
           }
     else
           {
            if(ch <= 'd' or ch >= 'z')
                  {
                   int ch;
                   ch = ch - 3;
                   return ch;
                  }
            else
                  {
                  char s;
                  switch(ch)
                            {
                            case 'a':
                            s = 'x';
                            break;
                            case 'b':
                            s = 'y';
                            break;
                            case 'c':
                            s = 'z';
                            break;
                            }
                  }          
            return ch;
}
}            

//Function 2 

char convPunct(char ch)
{
char s;
switch(ch)
{
case '0':
s = ',';
break;
case '1':
s = '.';
break;
case '2':
s = '$';
break;
case '3':
s = '&';
break;
case '4':
s = '%';
break;
case '5':
s = '*';
break;
case '6':
s = '(';
break;
case '7':
s = ')';
break;
case '8':
s = '?';
break;
case '9':
s = '!';
break;
}
}
//Function 3

char convDigit(char ch)
{
switch(ch)
{
case '!':
ch = '0';
break;
case ',':
ch = '1';
break;
case ')':
ch = '2';
break;
case '(':
ch = '3';
break;
case '?':
ch = '4';
break;
case '-':
ch = '5';
break;
case '&':
ch = '6';
break;
case '$':
ch = '7';
break;
case '.':
ch = '8';
break;
case '+':
ch = '9';
break;
}
}

//Function 4

char convRest(char ch)
{
if( int ch = 22)
{
    ch = ' ';
    return ch;
}

else if( int ch = 21)
{
     ch = '"\n"';
     return ch;
}

else
    return ch;
}
Much thanks go to spotswood for helping me create the complete caesar cipher. Now, I've created my whole program, designed to decode a specific message . However, it compiles just fine, but when data is inputted it just returns the exact same data as was entered (aka I enter 'c' it returns 'c' instead of 'z'). Does anybody know why?

you never change the value of ch.

IE ch = convDigit(ch);

or you can send it by reference
initialize convDigit ect like
char convDigit(char &ch)
and dont use the variable s, just change the value of ch.
__________________

Aumotocnic"An unfortunate member of the overclock.net insomnia club"

-- / T_he Rad / iohead F_a/n Club_--

Crucial Ballistix Club

System: The Mediocre Guy
CPU
E7200 @ 3.8ghz
Motherboard
Gigabyte P45 DS3
Memory
4GB Corsair XMS2
Graphics Card
Geforce 8800 GTS (600/900)
Hard Drive
250 gb hitachi Deskstar + 120gb Seagate
Power Supply
PC Power & Cooling Silencer 750 Quad
Case
Aspire X-Cruiser Black
CPU cooling
Zalman 9700
GPU cooling
Stock
OS
Windows xp
Monitor
ViewSonic Optiquest 20.1 inch 1650x1058
B-80 is online now   Reply With Quote
Old 10-16-09   #3 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,449

Rep: 200 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 173
Folding Team Rank: 292
Trader Rating: 24
Default

I changed my int main to this,

Code:
int main()
{
    char ch;
    cin >> ch;
    while (ch)
    {
          if (isalpha(ch))
                {
                 ch == revCaesar(ch);
                }
                
          else if (ispunct(ch))
                {
                 ch == convPunct(ch);
                }
                
          else if (isdigit(ch))
                {
                 ch == convDigit(ch);
                }
                
          else 
                {
                 ch == convRest(ch);
                }
                cout<<ch;
                cin>>ch;
    }
system ("pause");
return 0;
}
But I'm still having the same issue.
I also changed all of the 's' to ch in the switch statements. Any other ideas?
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions

Last edited by tofunater : 10-16-09 at 07:17 PM
tofunater is online now I fold for Overclock.net   Reply With Quote
Old 10-16-09   #4 (permalink)
ATI Enthusiast
 
gamervivek's Avatar
 
intel ati

Join Date: Oct 2007
Posts: 1,875

Rep: 166 gamervivek is acknowledged by manygamervivek is acknowledged by many
Unique Rep: 130
Trader Rating: 0
Default

Quote:
Originally Posted by tofunater View Post
I changed my int main to this,

Code:
int main()
{
    char ch;
    cin >> ch;
    while (ch)
    {
          if (isalpha(ch))
                {
                 ch == revCaesar(ch);
                }
                
          else if (ispunct(ch))
                {
                 ch == convPunct(ch);
                }
                
          else if (isdigit(ch))
                {
                 ch == convDigit(ch);
                }
                
          else 
                {
                 ch == convRest(ch);
                }
                cout<<ch;
                cin>>ch;
    }
system ("pause");
return 0;
}
But I'm still having the same issue.
I also changed all of the 's' to ch in the switch statements. Any other ideas?
just remove one = sign and it should run fine.
__________________
there are only 10 kind of people in this world, those who understand ternary, those who don't, and then those who don't give a damn.

I see in Fight Club the strongest and smartest men who've ever lived. I see all this potential, and I see squandering...

So bye-bye, miss american pie,gamervivek has left the building.

Ati Tray Tools vs CCC

System: living on the edge BSODs galore
CPU
e2140@3.2Ghz
Motherboard
abit IP35-E
Memory
4GB 667@800 5-5-5-15
Graphics Card
HIS IceQ4 4850
Sound Card
soundblaster live! 24-bit
Power Supply
Corsair 450VX@stock
CPU cooling
Q6600's HSF
OS
win xp 32 bit
gamervivek is offline   Reply With Quote
Old 10-17-09   #5 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,449

Rep: 200 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 173
Folding Team Rank: 292
Trader Rating: 24
Default

Alright, revised code is as follows:
Code:
#include <iostream>
#include <iomanip>
#include <ctype.h>
using namespace std;
char revCaesar(char);
char convPunct(char);
char convDigit(char);
char convRest (char);
int main()
{
    char ch;
    cin >> ch;
    while (ch)
    {
          if (isalpha(ch))
                {
                 ch = revCaesar(ch);
                }
                
          else if (ispunct(ch))
                {
                 ch = convPunct(ch);
                }
                
          else if (isdigit(ch))
                {
                 ch = convDigit(ch);
                }
                
          else 
                {
                 ch = convRest(ch);
                }
                cout<<ch;
                cin>>ch;
    }
system ("pause");
return 0;
}
//Function 1 - undoes the Caesar Cipher
char revCaesar(char ch)
{
     if(isupper(ch))
            
           {
            if(ch >= 'D' and ch <= 'Z')
                  {
                   ch = ch - 3;
                   return ch;
                  }
            else
                
                switch(ch)
                            {
                            case 'A':
                            ch = 'X';
                            break;
                            case 'B':
                            ch = 'Y';
                            break;
                            case 'C':
                            ch = 'Z';
                            break;
                            }
            return ch;
           }
     else if(ch >= 'd' or ch <= 'z')
          {
          ch = ch - 3;
          return ch;
          }
     else
         {
         switch(ch)
                   {
                   case 'a':
                   ch = 'x';
                   break;
                   case 'b':
                   ch = 'y';
                   break;
                   case 'c':
                   ch = 'z';
                   break;
                   }
         return ch;
         }
         
                            
            

}            

//Function 2 

char convPunct(char ch)
{

switch(ch)
{
case '0':
ch = ',';
break;
case '1':
ch = '.';
break;
case '2':
ch = '$';
break;
case '3':
ch = '&';
break;
case '4':
ch = '%';
break;
case '5':
ch = '*';
break;
case '6':
ch = '(';
break;
case '7':
ch = ')';
break;
case '8':
ch = '?';
break;
case '9':
ch = '!';
break;
}
}
//Function 3

char convDigit(char ch)
{
switch(ch)
{
case '!':
ch = '0';
break;
case ',':
ch = '1';
break;
case ')':
ch = '2';
break;
case '(':
ch = '3';
break;
case '?':
ch = '4';
break;
case '-':
ch = '5';
break;
case '&':
ch = '6';
break;
case '$':
ch = '7';
break;
case '.':
ch = '8';
break;
case '+':
ch = '9';
break;
}
}

//Function 4

char convRest(char ch)
{
if( int ch = 22)
{
    ch = ' ';
    return ch;
}

else if( int ch = 21)
{
     ch = '"\n"';
     return ch;
}

else
    return ch;
}
It correctly decodes A-Z and d-z, but nothin else is correct. Anybody else have any thoughts?
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions
tofunater is online now I fold for Overclock.net   Reply With Quote
Old 10-17-09   #6 (permalink)
Programmer
 
newbie1911's Avatar
 
Join Date: Jul 2008
Posts: 318

Rep: 19 newbie1911 Unknown
Unique Rep: 17
Trader Rating: 0
Default

function 2 and 3 didn't return a value after making the return ch; after the switch's it looks like it works. i have no idea if its working properly tho.
Code:
#include <iostream>
#include <iomanip>
#include <ctype.h>
using namespace std;
char revCaesar(char);
char convPunct(char);
char convDigit(char);
char convRest (char);
int main()
{
    char ch;
    cin >> ch;
    while (ch)
    {
          if (isalpha(ch))
                {
                 ch = revCaesar(ch);
                }
                
          else if (ispunct(ch))
                {
                 ch = convPunct(ch);
                }
                
          else if (isdigit(ch))
                {
                 ch = convDigit(ch);
                }
                
          else 
                {
                 ch = convRest(ch);
                }
                cout<<ch;
                cin>>ch;
    }
system ("pause");
return 0;
}
//Function 1 - undoes the Caesar Cipher
char revCaesar(char ch)
{
     if(isupper(ch))
            
           {
            if(ch >= 'D' && ch <= 'Z')
                  {
                   ch = ch - 3;
                   return ch;
                  }
            else
                
                switch(ch)
                            {
                            case 'A':
                            ch = 'X';
                            break;
                            case 'B':
                            ch = 'Y';
                            break;
                            case 'C':
                            ch = 'Z';
                            break;
                            }
            return ch;
           }
     else if(ch >= 'd' || ch <= 'z')
          {
          ch = ch - 3;
          return ch;
          }
     else
         {
         switch(ch)
                   {
                   case 'a':
                   ch = 'x';
                   break;
                   case 'b':
                   ch = 'y';
                   break;
                   case 'c':
                   ch = 'z';
                   break;
                   }
         return ch;
         }
         
                            
            

}            

//Function 2 

char convPunct(char ch)
{

switch(ch)
{
case '0':
ch = ',';
break;
case '1':
ch = '.';
break;
case '2':
ch = '$';
break;
case '3':
ch = '&';
break;
case '4':
ch = '%';
break;
case '5':
ch = '*';
break;
case '6':
ch = '(';
break;
case '7':
ch = ')';
break;
case '8':
ch = '?';
break;
case '9':
ch = '!';
break;
}
return ch;
}
//Function 3

char convDigit(char ch)
{
switch(ch)
{
case '!':
ch = '0';
break;
case ',':
ch = '1';
break;
case ')':
ch = '2';
break;
case '(':
ch = '3';
break;
case '?':
ch = '4';
break;
case '-':
ch = '5';
break;
case '&':
ch = '6';
break;
case '$':
ch = '7';
break;
case '.':
ch = '8';
break;
case '+':
ch = '9';
break;
}
return ch;
}

//Function 4

char convRest(char ch)
{
if( int ch = 22)
{
    ch = ' ';
    return ch;
}

else if( int ch = 21)
{
     ch = '"\n"';
     return ch;
}

else
    return ch;
}
__________________
90% of statistics are made up on the spot. including this one.
newbie1911 is offline   Reply With Quote
Old 10-17-09   #7 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,449

Rep: 200 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 173
Folding Team Rank: 292
Trader Rating: 24
Default

Quote:
Originally Posted by newbie1911 View Post
function 2 and 3 didn't return a value after making the return ch; after the switch's it looks like it works. i have no idea if its working properly tho.
Any idea why functions 2 and 3 don't return a value?
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions
tofunater is online now I fold for Overclock.net   Reply With Quote
Old 10-17-09   #8 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

Quote:
Originally Posted by tofunater View Post
Any idea why functions 2 and 3 don't return a value?
convPunct is trying to convert digits and convDigit is trying to convert punctuation.
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is online now   Reply With Quote
Old 10-17-09   #9 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,449

Rep: 200 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 173
Folding Team Rank: 292
Trader Rating: 24
Default

Changed, but now I'm outputting letters with annunciation symbols above them instead of symbols, and mathematical signs instead of numbers ...
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions
tofunater is online now I fold for Overclock.net   Reply With Quote
Old 10-17-09   #10 (permalink)
Programmer
 
newbie1911's Avatar
 
Join Date: Jul 2008
Posts: 318

Rep: 19 newbie1911 Unknown
Unique Rep: 17
Trader Rating: 0
Default

upper case letters seem to work fine.
__________________
90% of statistics are made up on the spot. including this one.
newbie1911 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 02:17 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.18050 seconds with 8 queries