Hello, i want to ask, messing words in array is a good way to encrypt data? or can someone very easy to brake it
here is an example
#include "stdafx.h"
#include <fstream>
using namespace std;
// Decleration for functions
void EncryptFile(char c[], int key1, int key2);
void DecryptFile(string filename, int key1, int key2);
char NewMessage[80];
int _tmain(int argc, _TCHAR* argv[])
{
// Array to store message
char Message[80];
// Prompt user type something
printf("Write a short story about you, less than 80 words.\n");
// Get wrods
gets(Message);
// Encrypt & Decrypt message
EncryptFile(Message, 1, 1);
DecryptFile("passwords.key", 1,1);
return 0;
}
void EncryptFile(char c[], int key1, int key2)
{
// Write Encrypted message to file
ofstream myf;
myf.open("passwords.key");
for(int i=0; c[i]; i++) {
c[i] = (c[i] + key1) * key2;
myf << c[i];
printf("%c", c[i]);
}
printf("\n");
myf.flush();
myf.close();
}
void DecryptFile(string filename, int key1, int key2)
{
// Open Message from file
ifstream myf;
myf.open(filename);
while(!myf.eof())
myf >> NewMessage;
for (int i=0; NewMessage[i]; i++) {
NewMessage[i] = (NewMessage[i] - key1) / key2;
printf("%c", NewMessage[i]);
}
printf("\n");
}
this part can be better, using a strong mathematic function, but for now i have this
NewMessage[i] = (NewMessage[i] - key1) / key2;
Using this
// Encrypt & Decrypt message
EncryptFile(Message, 1, 1);
DecryptFile("passwords.key", 1,1);
The encrypted message of abc is bcd because we add 1*1 = 1 in asii code ;p so it goes to next ;p