WHAT IS THE BEST EXPLANATION FOR THIS OUTPUT??

"HOW DOES THIS PROGRAM WORK?" AND "WHAT IS THE CONCEPT OF THIS PROGRAM??
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
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
[E] encipher
[D] decipher
[X] Exit

Enter choice: e(user input)
Enter message to encrypt: I LOVE YOU (user input)
Enter key: LOVE(user input)
The encrypted message: T ZJZP MJY
Back to main menu?
(Y/N) YES (return to menu if NO, program exits) : Y (user input)

Enter choice:d(user input)
Enter message to decrypt: T ZJZP MJY(user input)
Enter key: LOVE(user input)
The decrypted message is: I LOVE YOU
Back to main menu? (y/n): N (user input)THE PROGRAM WILL CLOSE.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Best explanation I can think of (that's not saying much, I am sleepy atm) is that this is program that encrypts user's messages with the help of a key. It looks simple but my sleepy brain can't decide what how the key affects the output. The program will also, given the key used to encrypt the message and the encrypted message, it is able to generate the original message.

See:
http://en.wikipedia.org/wiki/Cryptography
https://www.khanacademy.org/computing/computer-science/cryptography/crypt/v/intro-to-cryptography

After a bit of twiddling, voila!
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
#include <iostream>
#include <string>
using namespace std;

int main() {
    string message = "I LOVE YOU";
    string MASK = "LOVE";

    cout << "Encrypting message... = ";
    int curr_mask = 0;
    string encrypted = "";
    for (int pos = 0; pos < message.length(); pos++) {
        if (message[pos] == ' ') {
            encrypted.push_back(' ');
            continue;
        }
        encrypted.push_back(((message[pos] - 'A') + (MASK[curr_mask] - 'A')) % 26 + 'A');
        curr_mask = (curr_mask + 1) % MASK.length();
    }
    cout << encrypted << endl;
    
    cout << "Decrypting message... = ";
    curr_mask = 0;
    for (int pos = 0; pos < encrypted.length(); pos++) {
        if (encrypted[pos] == ' ') {
            continue;
        }
        message[pos] = (((encrypted[pos] - 'A') + 26 - (MASK[curr_mask] - 'A')) % 26 + 'A');
        curr_mask = (curr_mask + 1) % MASK.length();
    }
    
    cout << message << endl;

    return 0;
}
Last edited on
MR. THE KEY AFFECTS HOW THE MESSAGE WILL BE ENCRYPT

AND THE "I LOVE YOU" IS FROM THE USER INPUT AND ALSO THE "KEY"

EXAMPLE :

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/
this guy just wants us to do his homework. He's been posting for a few days now.
no im not.. i have a codes but i dont want to post it. because some of my classmate search the encryption and decryption in the google. ill try in and my post show in the google so i dont want to post my codes.

my problem is to defense my codes. some of the codes i didn't understand. can u help me to understand it? i send u in a private message.
@TARIKNEAJ

im a girl.. sorry :<
I couldnt care less lol
happy? i pm u the code of that output.

so i try to protect my output so don't judge me like that. :'(
So you have the code for the program, and yet when you ask how the program works you just show us the output of the program? Wtf? If you don't understand the program, make a thread and say so! If you don't understand the output, study the program!
Topic archived. No new replies allowed.