please help me

weqw
Last edited on
closed account (SECMoG1T)
if(isalpha(input[count]))
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
#include <iostream>
#include <string>
#include <cctype> // *** added: for isalpha, tolower
using namespace std;

int main()
{
    string input;
    // int count = 0, length; // *** postpone these till the variables are needed
                                        // and we know how to initialise them 

    cout << " Enter message to encypt:";
    getline( cin, input ) ; // *** missing semicolon

    const int length = ( int ) input.length(); // *** typo: length = ( int ) input.lenhth();

    for ( int count = 0; count < length; count ++ ) // for ( count = 0; count < length; count ++ )
    {
        if( isalpha( input[count] ) ) // if( isalpha[input] ) ) // *** input[count] is the character at position count
        {
            input[count] = tolower ( input[count] );

            for ( int i = 0; i < 26; i++ ) // *** is this loop intended?
                                           // assuming that the beginner's assumption that
                                           // input[count]++ will get us to the next character in the classical latin alphabet
                                           // holds, repeatiung this 26 times will just get us back to the original character
            {
                if ( input[count] == 'z' )
                    input[count] = 'a';
                else
                    input[count]++; // *** warning: non-portable, and may lead to undefined behaviour
                                    // (though this may be just what the typical teacher expects you to do)

            }
        }
    }

    cout << "results:" << input << endl;
}
thank you :))

MR. if i will put Cout<<"Enter key:" that represent as a password? how to make code from it?
Last edited on
> if i will put Cout<<"Enter key:" that represent as a password? how to make code from it?

How do you intend to use the password entered by the user?
(An example of a password entered by the user and how it is used would help.)
yes mr. entered by the user.

about my private message to you mr. i have a code from it but i dont know how to explain it from the question "HOW DOES THE PROGRAM WORK?"
mr. JLBorges please answer my private message that i've send to you
"HOW DOES THE PROGRAM WORK?" OR "WHAT IS THE CONCEPT OF THIS PROGRAM?"

BECAUSE MR. I NEED TO DEFENSE IT TO MY PROF. THIS COMING TUESDAY.. HOPE U UNDERSTAND MY SITUATION.

THIS IS THE CODE OF THIS OUTPUT:

[E] encipher
[D] decipher
[X] Exit

Enter choice: e(user input)
Enter message to encrypt: (user input)
Enter key:user input)
The encrypted message:
Back to main menu?
(Yes/No) YES (return to menu if NO, program exits) : y (user input)

Enter choice:d(user input)
Enter message to decrypt:(user input)
Enter key:(user input)
The decrypted message is:
Back to main menu? (y/n): N (user input)


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@



**** Deleted the code contained in the private message.
**** Fink: PLEASE DELETE THE CODES YOU COMMENT FROM MY CODES
**** Fink: BECAUSE IT IS VERY IMPORTANT TO ME.


> "HOW DOES THE PROGRAM WORK?"

It does not work; the program is ill-formed; it contains erroneous constructs that are required to be diagnosed as errors by conforming implementations.

Lines 38, 128:
error: variable length arrays are a C99 feature
http://coliru.stacked-crooked.com/a/f5a8e3b13de5060d

You are already using std::string in your program (you need to #include <string>); so use them everywhere instead of relying on linuxisms.


> "WHAT IS THE CONCEPT OF THIS PROGRAM?"

You need to first understand what the assignment asks you to do, before you look at or attempt to write any code.

Can you explain these in plain English and/or in pseudo-code:
How is the plaintext string enciphered? How is the ciphertext deciphered?
Last edited on
How is the plaintext string enciphered?

THE PLAINTEXT STRING will be ENCIPHER because of the password serves as a KEY.

example:

the user input message to encrypt "I LOVE YOU" and the password is "LOVE.

to encrypt our first letter in message is "I" and the first letter in our pass is "L" the program will stop in letter "L"

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
@@@@@@@,,,A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

soln. I=A since the program will stop in letter "L" because of the password. A-L. the letter "I" will be encipher to letter "T" because letter T stop on L.

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
@@@@@@@@@@,,A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
*same as the second letter of the message and the password.
"L"is our 2nd letter of our message and "O" is our 2nd letter of our password.
L=A, the program will stop in letter "O" and the letter "Z" is the encrypt of the letter L because O is stop on the letter "Z"

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

>"How is the ciphertext deciphered?"

same solution to the ENCIPHER BUT ITS BACKWARD.

THE ENCRYPTED MESSAGE IS "T ZJZP MJY and our password is same "LOVE"


@@@@@@,A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Z Y X W V U T S R Q P O N M L K J I H G F E D C B A

since out 1st letter is "T" and the 1st letter of pass. is "L". T=A and it will stop in letter L backward, so that the decrypt of "T" is "I" because L stop on the letter "I"

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Z Y X W V U T S R Q P O N M L K J I H G F E D C B A

same as the 2nd letter "Z" and the 2nd letter of our pass is "O". Z=A and it will stop in the letter O. so that the decrypt of letter "Z" is "L" because O stop in letter "L".


did you get my post?

IF YOU CAN MINIMIZE THE LINE OF THE CODES. CAN U CHANGE IT? PLEASE BECAUSE THAT CODES IS HARD TO EXPLAIN.. BY THE WAY THANK YOU FOR HELPING ME.. FOR THIS CODE.

these our compiler that we use: http://sourceforge.net/projects/orwelldevcpp/
Last edited on
> PLEASE DELETE YOUR LAST REPLY ON ME. IT WILL GET THE CODE BY THE OTHERS

I've edited the post to remove the code that was part of the private message.

However, I don't see why I should delete the entire post.

I'm glad that you could mark the topic as 'solved'; I suppose that 'the teddy bear effect' can be extended to 'explain to someone else what the program is expected to do'.

Another effective technique is to explain your code to someone else. This will often cause you to explain the bug to yourself. Sometimes it takes no more than a few sentences, followed by an embarrassed "Never mind, I see what's wrong. Sorry to bother you.'' This works remarkably well; you can even use non-programmers as listeners.

One university computer center kept a teddy bear near the help desk. Students with mysterious bugs were required to explain them to the bear before they could speak to a human counselor.

- Brian W. Kernighan and Rob Pike in 'The Practice of Programming'
you need to edit your post because some of my classmate haven't yet the codes. and my prof. are strict when it come at the same codes. sorry..


some of the codes i've understand and some not :) thank you .. :)

its hard to understand some of the codes because i am Bachelor of secondary education major in mathematics. since we have a programming in our requisition form. and it is 5units. a major subject so i need to defense my codes. :'(
Topic archived. No new replies allowed.