I need help Please

closed account (3qD2y60M)
Hi everybody,
I have just started learning c++ and in this specific post I am trying to figure out encryption function. Here is my code:


// I need to define the encript function hereĀ 
// the exception of A | a which should return a 9;

#include "stdafx.h"
#include <iostream>

using namespace std;

char encript(char &alph)
{
char result;
char alphabet[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";

for (int j = 0; j<alphabet.length; j++)
{
if (alph = 'z')
{
result = '9';
}
else
{
if (alph == alphabet[j])
{
result = alphabet[j - 1];
}
}
}
return result;
}

bool checkit(char inChar)
{
if (inChar != '9') return true;
return false;
}
int main(int argc, char* argv[])
{
char c1 = 'I';
char c2 = 'B';
char c3 = 'M';
char aChar;
char var;

cout << "The characters " << c1 << c2 << c3 << " are ";
cout << encript(c1) << encript(c2) << encript(c3) << endl;

do{
cout << "Enter a character ";
cin >> aChar;
var = aChar;
cout << " achar encripted is " << encript(aChar);
cout << " achar was " << var << " now is " << aChar << endl;

} while (checkit(aChar));
return 0;
}
Last edited on
closed account (28poGNh0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# include <iostream>
# include <cstdlib>
using namespace std;

// I need to define the encript function here
// the exception of A | a which should return a 9; if you think at this way
// better to not return anything and just add another condtion to the do while loop
// ( checkit(var)&&var!='A');

void encript(char &ch)
{
    while(true)
    {
        int rndNbr = rand()%255;

        if(rndNbr>=128&&rndNbr<=150)
        {
            ch = char(rndNbr);
            break;
        }
    }
}

bool checkit( char inChar )
{
    if( inChar != '9' ) return true;

    return false;
}

int main(int argc, char* argv[])
{
    char aChar;
    char var;

    do{
        cout << "Enter a character ";
        cin >> aChar;
        var = aChar;
        // cout << " achar encripted is " <<    No need for this one ;

        encript(aChar);
        cout << " achar was " << var << " now is " << aChar << endl;
    }while ( checkit(var) );// Turn aChar to var because aChar encripted right now and never get 9
                            // in our case , ps to end the loop enter 9

    return 0;
}
closed account (3qD2y60M)
I appreciate your help. I am going to rewrite my function the way that it returns the previous letter . For example I B M and returns H A L. Do you recommend anthing?
Last edited on
closed account (28poGNh0)
Do you know ? this is almost like rot13 encryption, google it to see

Do you recommend a door ..

I recommend you to make errors as much as you can,thats how I learned so far!
Topic archived. No new replies allowed.