Can you try out my project?

This was made with Microsoft Visual Studio, so you might have to change the headers or something if you use something else. What makes this encryptor unique is that it takes a password from the user and uses it to encrypt the text. Sorry for my lack of comments. I don't think this project is that hard to understand anyway. Then again I'm the one who wrote it.

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// mmmph.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
#include <time.h>
#include <stdio.h>

using namespace std;
ofstream out_stream;
ifstream in_stream;
int num1, num2, num3;
string words, lines;
string stop;
string what;
ifstream in_passy;
ofstream out_passy;
string encryptor(string words);
string password;
int sum;
string hope;


string encryptor(string words, string password)
{
	{

		string output;

		string::iterator it;
		string::iterator it2;


		/*while( !out_stream.eof())
		{}
		*/
		sum =0;
		for(it=password.begin(); it != password.end();it++)
		{
			char c=*it;
			int n= c;
			sum += n;
		}

		for(it2=words.begin(); it2 != words.end();it2++)
		{
			char c=*it2;
			int n= c;
			int n2 =  (n+sum)%256;
			char c2= n2;
			output += c2;
		}


		return output;


	}
}



string decryptor(string words, string password)
{
	{

		string output;

		string::iterator it;
		string::iterator it2;
		out_stream.open("encrypt.txt");

		/*while( !out_stream.eof())
		{



		}
		*/
		sum =0;
		for(it=password.begin(); it != password.end();it++)
		{
			char c=*it;
			int n= c;
			sum += n;
		}

		for(it2=words.begin(); it2 != words.end();it2++)
		{
			char c=*it2;
			int n= c;
			int n2 =  (n-sum)%256;
			char c2= n2;
			output += c2;

		}



		return output;


	}
}




int Intro()
{
	string ans;
	cout<<"Welcome to Matt G's program which will save your message and turn it into a     secret encryption(lock)."<<endl;
	system("pause");
	system("cls");
	while(true)
	{
	cout<<"Now do you want to lock a message or unlock it?"<<endl;
	getline(cin, ans);
		if (ans=="lock") 
		{
			return 1;
		}
		if (ans=="unlock") 
		{
		return 2;
		}
		else 
		{
		}
	}
}

string getText()
{
	string x;
	cout<<"Please type in a message to be turned into secret code."<<endl;
	getline(cin, x);
	return x;

}

string pass()
{	
	out_passy.open("password.txt");
	cout<<"Please enter in a password for the message."<<endl;
	getline(cin, password);
	out_passy<<encryptor(password, "erjktgjkdofgjdfgg4a564f5g348g84gdfga48er4gf85g74r4r4t");
	return password;

}

int _tmain(int argc, _TCHAR* argv[])
{
	int ans= Intro();



	if(ans==1) 
	{
		out_stream.open("encrypt.txt");
		out_stream<<encryptor(getText(), pass());
		//out_passy<<hope;
		system("pause");
		system("cls");
		cout<<"After you end this program by pressing any key you can go into encrypt.txt and  look at the message(now locked). You can also look at the password which is     always locked. Run this program again and this time go to unlock to get your    message back to normal."<<endl;
		system("pause");
	}
	else if(ans==2)
	{	string SnP;
	string PnS;
	in_stream.open("encrypt.txt");
	in_passy.open("password.txt");
	in_stream>>SnP;
	out_stream<<decryptor(SnP, pass());
	in_passy>>PnS;
	//out_passy<<decryptor(PnS, "erjktgjkdofgjdfgg4a564f5g348g84gdfga48er4gf85g74r4r4t");
	cout<<"Now you can go back to encrypt.txt and you will find the original message.      Thank you for using this program!"<<endl;
	system("pause");
	}

	return 0;
}


I know there is a lot of system() in that code, but I didn't know not to use it when I made that code.
Last edited on
Also please try out my other project. This one was too big to fit in a post here so it is in a txt file that you can download.

http://www.megafileupload.com/en/file/362924/All-Brawl-txt.html
You do know that you can do mathematical operations directly on char data types right? As interesting as this looks though it's just a mono-alphabetic Caesar shift cipher. Because you're using the same value to encrypt every character you're leaving it wide open to a simple frequency analysis attack, and unfortunately a longer and\or more complex password in these types of ciphers won't make it any more secure. It's not a bad first try though.
Topic archived. No new replies allowed.