Help with my program

hello everyone, so i was wondering if i can get help with my program.
Ok so i'm suppose to create a program that performs different types of encryption or decryption.

- firstmost, i must ask the user if he/she want to perform encryption or decryption
-if he/she wants to perform encryption, i should be able to find out if he/she wants to use the "rot" method or "cryptogram" method
- if "rot" method is selected, I need to ask for the encryption key (for example if he/she enter 12, it means that"rot12" will be used to do the encryption)

-picking the cyptogram method means that I should open the cyptogram text file where the cyptogram string is stored
- the cyptogram text file contain 26 letter of the alphabet mixed up where the first letter corresponds to 'a', second letter corresponds to 'b' and so on.
example of cyptogram file:
srnoefmxbgathzqldpuvckijwy
's' corresponds to a, 'r' to b, finally 'y' to z.

--the same precedure should be followed if he/she wants to perform decryption. i need to ask he/she which method to use ("rot" or "cyptogram"). then i suppose to write the routines that takes an encrypted file and performs the decryption in order to get the original file back.

My original input file named "original.txt" contains the following message:

the world has become a very different place than what was some yhears back. this may be because society has advanced into much greater society, but somehow there's still much much more that society as whole needs to learn.

my task is to:
1. encrypt the original message using "rot12" and call the file encryption01.txt

2. encrypt the original message using the following cyptogram from before and call the file encryption02.txt :
srnoefmxbgathzqldpuvckijwy

3. decrypt "encrypttion01.txt" using rot12(shifting every alphabet to the left 12 places and calling it "decryption01.txt")

4. decrypt "encryption02.txt" using the cyptogram from task 2, and call it "decryption02.txt"

**decryption01.txt and decryption02.txt should be identical to the original file that i used for encryption

---------------------------------------------------

OK, so what I have in my following code is how to do task 1 (encryption using rot), I want to do task 3 right now (decryption using rot), any help, i don't know how it's suppose to look like, so any tips, examples, corrections, etc. would be much appreciated.

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
#ifndef A1class_H
#define A1class_H

#include <iostream>
using namespace std;

class Security
{
 private:
  int Rot;
  string CryptCmnd;


 public:
  string EncryptUsingRot(string word, int rotnum);
  string EncryptUsingCrypto(string word, int rotnum);
  string DecryptUsingRot(string word);
  string DecryptUsingCrypto(string word);
  void Driver();
  bool DoRotEncryption();
  bool DoRotDecryption();
  bool DoCryptoEncryption();
  bool DoCryptoDecryption();
  int GetARotNumber();
};

#endif 



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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef A1functions_CPP
#define A1functions_CPP

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

#include "A1class.h"

//this asks the user what method he/she wants to use
void Security::Driver()
{
  cout << "______________________________" << endl;
  cout << "1: Encrypt a message using rot " << endl;
  cout << "2: Decrypt a message using rot " << endl;
  cout << "3: Encrypt a message using crypto " << endl;
  cout << "4: Decrypt a message using crypto " << endl;
  cout << "______________________________" << endl;
  int choice;
  cout << "Enter your choice: ";
  cin >> choice;

  if(choice == 1)
    {
      DoRotEncryption();
    }
  else if(choice == 2)
    {
      DoRotDecryption();
    }
  else if(choice == 3)
    {
      DoCryptoEncryption();
    }
  else if(choice == 4)
    {
      DoCryptoDecryption();
    }
  else
    {
      cout << "Invalid choice! " << endl;
    }
}

//------------------------------------------------------------------------------------

bool Security::DoRotEncryption()
{
  int RotNumber = GetARotNumber();
  ifstream fin;
  ofstream fout;
  fin.open("Encrypt01.txt");
  fout("Decrypt.txt");

  string word;
  while(fin >> word)
    {
      string eWord = EncryptUsingRot(word, RotNumber);
      fout << eWord << " ";
    }
  return true;
}

//------------------------------------------------------------------------------------
//this asks the user what rot number he/she wants to use 
int Security::GetARotNumber()
{
  int num = 0;
  while((num < 1) || (num > 25))
    {
      cout << "Enter a rot number 1 and 25( ): ";
      cin >> num;
    }
  return num;
}

//------------------------------------------------------------------------------------

string Security::EncryptUsingRot(string word, int rotnum)
{
  string eWord = word;
  eWord = tolower(eWord);

  for(int i < 0; i < eWord.size(); i++)
    {
      char ch = eWord[j];
      int j = ch;
      j = j + rotnum;

      if(j > z)
        {
          j = j - 26;
          eWord[i] = j;
        }
      return eWord;
    }
}

//------------------------------------------------------------------------------------


#endif 



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef A1main_CPP
#define A1main_CPP

#include <iostream>
using namespace std;

#include "A1functions.C"

int main()
{
  Security msg;
  msg Driver();

  return 0;
}

#endif 
Last edited on
I think that string DecryptUsingRot(string word); and bool DoRotDecryption(); should be somewhat similar because decryption suppose to get the original message from the encryption, but instead of adding rot12 as you see in encryption, you will need to subtract rot12 for decryption in order to get back to the original message, i just don't know how similar it is or how it's suppose to look like


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
bool Security::DoRotEncryption()
{
  int RotNumber = GetARotNumber();
  ifstream fin;
  ofstream fout;
  fin.open("Encrypt01.txt");
  fout("Decrypt.txt");

  string word;
  while(fin >> word)
    {
      string eWord = EncryptUsingRot(word, RotNumber);
      fout << eWord << " ";
    }
  return true;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
string Security::EncryptUsingRot(string word, int rotnum)
{
  string eWord = word;
  eWord = tolower(eWord);

  for(int i < 0; i < eWord.size(); i++)
    {
      char ch = eWord[j];
      int j = ch;
      j = j + rotnum;

      if(j > z)
        {
          j = j - 26;
          eWord[i] = j;
        }
      return eWord;
    }
}
Make an attempt?
Sure, here's what I attempted

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
bool Security::DoRotDecryption()
{
  int RotNumber = GetARotNumber();
  ifstream fin; ofstream fout;
  fin.open("Encrypt01.txt"); fout("Encrypt.txt");

  while(fin >> word)
    {
      string eWord = DecryptUsingRot(word, rotnum);
      cout << eWord << " ";
    }
  return true;
}


//------------------------------------------------------------------------------------

string Security::DecryptUsingRot(string word, int rotnum)
{
  string eWord = word;
  eWord = tolower(eWord);

  for(int i < 0; i < eWord.size(); i++)
    {
      char ch = eWord[i];
      int j = ch;
      j = j - rotnum;

      if(j > z)
        {
          j = j - 26;
          eWord[i] = j;
        }
      return eWord;
    }
}
What is z?

You just subtracted a number from j. Do you think checking to see if it's greater than something after that operation is useful?

Do this stuff on paper before you start writing code. What happens to a character when I encode it? What needs to happen to decode it?
Topic archived. No new replies allowed.