Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Encrypting

Name: Anonymous 2010-10-04 0:20

What's your thoughts on encrypting multiplying characters four at a time by matrix then decrypting using A^(-1) as devision in the same fasion.

Obviously this is private key if the matrix is set up on opening of the program.

What you guys do? what next?

Name: OP 2010-10-04 14:41

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

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List