>>3
hmm:
/*
needs
- completing (full streaming sentences)
- put in files[header/source]
- done for more than four letters
*/
#include "stdafx.h"
#include "gwin.h"
#include <iostream>
#include <string>
using namespace std;
// global rules for matrixs
// MATRIX_name = [a,b,c,d]
class Criptic
{
public:
double encoded[100];
string Encrypt(string word);
string Decrypt(string word);
void SetCodes();
private:
double ME[4];//MATRIX encoder
double MEM1[4];//MATRIX encoder to the minus 1
// MATRIX[0,1,2,3]
// MATRIX[a,b,c,d]
};
void Criptic::SetCodes()
{
ME[0] = 3.0;
ME[1] = 3.0;
ME[2] = 7.0;
ME[3] = 5.0;
MEM1[0] = (-(5.0/6.0));
MEM1[1] = (1.0/2.0);
MEM1[2] = (7.0/6.0);
MEM1[3] = (-(1.0/2.0));
};
string Criptic::Encrypt(string word)
{
string temp = "0000";
int i = 0;
int counter = 0;
do
{
if(counter == 3)
{
temp[counter] = word
[i];
counter = 0;
double aM = (double) temp[0];
double bM = (double) temp[1];
double cM = (double) temp[2];
double dM = (double) temp[3];
encoded[i-3] = (aM*ME[0])+(bM*ME[2]);
encoded[i-2] = (aM*ME[1])+(bM*ME[3]);
encoded[i-1] = (cM*ME[0])+(dM*ME[2]);
encoded
[i] = (cM*ME[1])+(dM*ME[3]);
word[i-3] = encoded[i-3];
word[i-2] = encoded[i-2];
word[i-1] = encoded[i-1];
word
[i] = encoded
[i];
++i;
}
if(counter < 3)
{
temp[counter] = word
[i];
}
++counter;
++i;
}while(i < word.size()); // word
[i] != '\0'
return word;
};
string Criptic::Decrypt(string word)
{
double tempNUMS[4];
int ii = 0;
int counter = 0;
do
{
if(counter == 3)
{
tempNUMS[counter] = encoded[ii];
counter = 0;
double aM = (double) tempNUMS[0];
double bM = (double) tempNUMS[1];
double cM = (double) tempNUMS[2];
double dM = (double) tempNUMS[3];
word[ii-3] = (aM*MEM1[0])+(bM*MEM1[2]);
word[ii-2] = (aM*MEM1[1])+(bM*MEM1[3]);
word[ii-1] = (cM*MEM1[0])+(dM*MEM1[2]);
word[ii] = (cM*MEM1[1])+(dM*MEM1[3]);
++ii;
}
if(counter < 3)
{
tempNUMS[counter] = encoded[ii];
}
++counter;
++ii;
}while(ii < word.size()); // word
[i] != '\0'
return word;
};
void DisplayCode(string word);
int main()
{
string words;
words = Gwin.getText(4);
Criptic code;
code.SetCodes();
//----------------------------
//encrypt tht mo fo'
words = code.Encrypt(words);
DisplayCode(words);
//----------------------------
//----------------------------
//decrypt tht mo fo'
words = code.Decrypt(words);
DisplayCode(words);
//----------------------------
// Finally, wait for a key to be pressed
Keyboard.getch();
return 0;
}
void DisplayCode(string word)
{
Gwin.writeString(" - ");
Gwin.writeString(word);
};