|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
Complete c++ decode program
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#11 (permalink) | ||||||||||||||
|
Security Sleuth
![]() |
Shift cipher, classic. Why not throw your own spin on it?
__________________
Quote:
Proud Member of the Linux Gaming CommunityI am your friend.
|
||||||||||||||
|
|
|
|
|
#12 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
capitals all work, and lowercase d-z work. Everything else is fubar'd
|
|||||||||||||
|
|
|
|
|
#13 (permalink) |
|
Programmer
|
found the problem with lover case ...
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;
}
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 convDigit(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 convPunct(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;
}
Code:
ch >= 'd' && ch <= 'z' Code:
ch >= 'd' || ch <= 'z'
__________________
90% of statistics are made up on the spot. including this one.
Last edited by newbie1911 : 10-17-09 at 04:06 PM |
|
|
|
|
|
#14 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
that did it newbie, thanks. Any thoughts on the symbols and numbers?
|
|||||||||||||
|
|
|
|
|
#15 (permalink) |
|
Programmer
|
couldn't find an bugs now. im confused about one part tho. why does it work with char arrays? i thought you needed to make a pointer to a char to input strings. also why does it go through every char in the array ?
__________________
90% of statistics are made up on the spot. including this one.
|
|
|
|
|
|
#16 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
Not quite sure what you mean by all of that newbie, but here is a link to the assignment -->http://www.cs.niu.edu/~abyrnes/csci240/pgms/240pgm6.htm
|
|||||||||||||
|
|
|
|
|
#17 (permalink) | |||||||||
|
ATI Enthusiast
![]() |
seem to be working fine for me.
__________________
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... old man look at my life, I'm a lot like you. Ati Tray Tools vs CCC
|
|||||||||
|
|
|
|
|
#18 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
Really? you run this:
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' 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;
}
}
//Function 2
char convDigit(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 convPunct(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;
}
|
|||||||||||||
|
|
|
|
|
#19 (permalink) |
|
Programmer
|
working perfectly fine for me. and the only things i changed from ur code is && instead of and also || instead of or ( visual c++ ) and i added
Code:
return ch;
__________________
90% of statistics are made up on the spot. including this one.
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|