What type of Cipher i got?

closed account (zb5L1hU5)
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
void EncryptOption() //If option 1 is choosen, encryption begins 
{ //declare variables// 
	char Pass[40], name[40]; 
	int a,b,x,y;
	const char* filename="Plaintext.txt";   //name of file
      ifstream infile(filename); 
                
 
  
//prompt for password// 
cout<<"Please enter your password:\n"; 
cin>>Pass; 
  
x=strlen(name); 
y=strlen(Pass);
ofstream outfile;
outfile.open("encrypt.txt",ios::ate);
  
for(a=0,b=0; a<x; a++,b++){ 
if (b>=y) 
b=0; 
name[a]=name[a]+Pass[b]; 
} 
outfile<<endl<<name; 
cout<<endl;
outfile.close();
cout<<"Encryption is finished!\n"; 
  
exit (0); 
}


Someone tell me what type of cipher this is please.
That's a variant of the additive cipher.
closed account (zb5L1hU5)
Like a stream cipher?
What you are trying for I've heard is called a "Key Cipher" or a "Keyword Cipher". Technically it could also be a "Vigenère Cipher" since the char in the password is converted to an int to get your new letter.

In case you want to expand on this project (since it is pretty cool for a beginner), you have a pretty weak version of this cipher. Keep in mind your password encrypts the plain text in a patterned loop and when it hits a while space name a becomes the ASCII numerical version of that letter in your password. The shorter the length of your password compared to the length of the text being encrypted, the more vulnerable your key and therefore your message becomes.

EDIT: I wouldn't call this a stream cipher since you're providing a key instead of relaying on a psuedo-random generator.
Last edited on
closed account (zb5L1hU5)
Thanks Computergeek01!!

I have done some fiddling...with my code and come up with something that might work for what I am trying to do.

But i have become stuck. I can read from a plaintext file and encrypt it outputting it to a file called encrypt. But when i come to decrypt that file, i cannot.
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include "conio.h"

using namespace std;

void encrypt();
void option(int opt);
void EncryptOption();
void DecryptOption();
void EXIT(); 
int main()
{
	encrypt();
	return 0;
}

void encrypt()
{
	int opt;
	
	do
	{
		cout << "WELCOME TO THE ENCRYPTOR!!.\n\n";
		cout << "Please choose one of the following...\n";
		cout << "1: Encryption\n";
		cout << "2: Decryption\n";
		cout << "3: Exit\n";
		cin  >> opt;
		cin.ignore(80,'\n'); //this reads what the user chose
        option(opt);//sends the answer to option
     }while(opt!=3);//program keeps going until the user chooses exit
}//end of this function 

void option(int opt)
{
     switch (opt)//Go through the options
     {
          case 1:
               EncryptOption();
               break;
          case 2:
               DecryptOption();
               break;
          case 3:
               EXIT();
               break;
          default://If anything other than 1,2,3 is chosen
               cout << "The option you have chosen was not listed, please try again.\n";
               break;
     }
}//end of case functions

void EncryptOption() //If option 1 is choosen, encryption begins 
{ //declare variables// 
	char Pass[40], name[40]; 
	int a,b,x,y;
	const char* filename="Plaintext.txt";   //name of file
      ifstream infile(filename); 
                  
	//prompt for password// 
	cout<<"Please enter your Key:\n"; 
	cin>>Pass; 
	  
	x=strlen(name); 
	y=strlen(Pass);
	ofstream outfile;
	outfile.open("encrypt.txt",ios::ate);
	  
	for(a=0,b=0; a<x; a++,b++)
	{ 
		if (b>=y) 
		b=0; 
		name[a]=name[a]+Pass[b]; 
	} 
	outfile<<endl<<name; 
	cout<<endl;
	outfile.close();
	cout<<"Encryption is finished!\n"; 

	exit (0);
}

void DecryptOption()// If option 2 is chosen, decryption begins
{ 
//declare variables// 
char Pass[40], name[40]; 
int a,b,x,y;
 const char* filename="encrypt.txt";   //name of file
      ifstream infile(filename);   
//prompt for password// 
cout<<"Please enter your Key:\n"; 
cin>>Pass; 
  
x=strlen(name); 
y=strlen(Pass); 
  
for(a=0,b=0; a<x; a++,b++){ 
if (b>=y) 
b=0; 
name[a]=name[a]-Pass[b]; 
} 
cout<<endl<<name; 
cout<<endl; 
cout<<"Decryption is finished!\n"; 
  
exit (0); 
}  

void EXIT()// If option 3 is chosen, program closes.
{
}






Any help greatly appreciated!!
Last edited on
That's a good amount of tinkering in just an hour. Since you're reversing your code and not trying to crack the cipher that made it I think I can help you.

I'm guessing that when you execute your DecryptOption(..) function you just get a bunch of numbers? I'm looking up how to turn those back into letters now.

EDIT: I'm reading your code now and I don't see where you take the input from infile and assign it to anything.

REDIT: Erm, now that I look at it you don't really encrypt the data from your EncryptOption(...) function because the data being read in doesn't look like it's being assigned to your name array. What you are getting for output must be garbage data.
Last edited on
Ah! Here it is:

http://www.cplusplus.com/doc/tutorial/typecasting/

You'll want to read up on type casting since you can't really add characters together. I'll poke around with it and if I come up with something before I get bored I'll post it for ya.
closed account (zb5L1hU5)
That's why I was getting random symbols in encrypt file. I'll look into that typecasting now. Thanks so much again!

EDIT: It wasn't decrypting my plaintext file just the passkey that followed symbols and number 9? I am a beginner in c++ but i had this menu style from previous years tutorial work and sort of bashed it together. Obviously missing some important parts.

BTW: you are legend for helping me out like this...learnt more from you than i have my previous lecturers! lol!
Last edited on
Topic archived. No new replies allowed.