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;
}
|