#include <iostream > using namespace std; void encrypt( char [ ] ); // prototypes of functions used in the code void decrypt( char [] ); int main( ) { // create a string to encrypt char string[ ] = "zyxwvust"; cout << "Original string is: " << string << endl; // call to the function encrypt( ) cout << "Encrypted string is: "; encrypt( string ); cout<<string<<endl; cout<<"Decrypted string is: "; decrypt (string); cout<<string<<endl; return 0; }// main //encrypt data void encrypt (char e[] ) { for( int i=0; e[i] != '\0'; ++i ) {switch (e[i]) { case 'a': case 'A': e[i]+=25; case 'b': case 'B': e[i]+=23; case 'c': case 'C': e[i]+=21; break; case 'd': case 'D': e[i]+=19; break; case 'e': case 'E': e[i]+=17; break; case 'f': case 'F': e[i]+=15; break; case 'g': case 'G': e[i]+=13; break; case 'h': case 'H': e[i]+=11; break; case 'i': case 'I': e[i]+=9; break; case 'j': case 'J': e[i]+=7; break; case 'k': case 'K': e[i]+=5; break; case 'l': case 'L': e[i]+=3; break; case 'm': case 'M': e[i]+=1; break; case 'n': case 'N': e[i]-=1; break; case 'o': case 'O': e[i]-=3; break; case 'p': case 'P': e[i]-=5; break; case 'q': case 'Q': e[i]-=7; break; case 'r': case 'R': e[i]-=9; break; case 's': case 'S': e[i]-=11; break; case 't': case 'T': e[i]-=13; break; case 'u': case 'U': e[i]-=15; break; case 'v': case 'V': e[i]-=17; break; case 'w': case 'W': e[i]-=19; break; case 'x': case 'X': e[i]-=21; break; case 'y': case 'Y': e[i]-=23; break; case 'z': case 'Z': e[i]-=25; break; case ',': e[i] = e[i]; break; case '.': e[i] = e[i]; break; case '?': e[i] = e[i]; break; case ' ': e[i] = e[i]; break; case'!': e[i] = e[i]; break; case'\0': i = 50; break; } } } // encrypt void decrypt( char f[] ) { for( int j=0; f[j] != '\0'; ++j ) {switch (f[j]) { case 'a': case 'A': f[j]+=25; case 'b': case 'B': f[j]+=23; case 'c': case 'C': f[j]+=21; break; case 'd': case 'D': f[j]+=19; break; case 'e': case 'E': f[j]+=17; break; case 'f': case 'F': f[j]+=15; break; case 'g': case 'G': f[j]+=13; break; case 'h': case 'H': f[j]+=11; break; case 'i': case 'I': f[j]+=9; break; case 'j': case 'J': f[j]+=7; break; case 'k': case 'K': f[j]+=5; break; case 'l': case 'L': f[j]+=3; break; case 'm': case 'M': f[j]+=1; break; case 'n': case 'N': f[j]-=1; break; case 'o': case 'O': f[j]-=3; break; case 'p': case 'P': f[j]-=5; break; case 'q': case 'Q': f[j]-=7; break; case 'r': case 'R': f[j]-=9; break; case 's': case 'S': f[j]-=11; break; case 't': case 'T': f[j]-=13; break; case 'u': case 'U': f[j]-=15; break; case 'v': case 'V': f[j]-=17; break; case 'w': case 'W': f[j]-=19; break; case 'x': case 'X': f[j]-=21; break; case 'y': case 'Y': f[j]-=23; break; case 'z': case 'Z': f[j]-=25; break; case ',': f[j] = f[j]; break; case '.': f[j] = f[j]; break; case '?': f[j] = f[j]; break; case ' ': f[j] = f[j]; break; case'!': f[j] = f[j]; break; case'\0': j = 50; break; } } } // encrypt |
|
|
#include <iostream> using namespace std; int main() { cout << "Hello world!\n"; return 0; } |
|
|
|
|
|
|
s -- a string i, n, x, y -- integers f -- a file b -- a boolean c -- a character |