Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication5.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <wctype.h>
- #include <stdio.h>
- #include <ctype.h>
- // the file is C://temp//New Text Document.txt
- using namespace std;
- //arraymatrix for decoding-encoding
- char arraymatrix0[5] = { 'H','A','P','I','N' };
- char arraymatrix1[5] = { 'E','S','B','C','D' };
- char arraymatrix2[5] = { 'F','G','J','K','L' };
- char arraymatrix3[5] = { 'M','O','Q','R','T' };
- char arraymatrix4[5] = { 'U','V','W','X','Y' };
- // needed special char and numbers and space
- char arraymatrix5[1] = { (char)' ', };
- char arraymatrix6[5] = { '1','2','3','4','5' };
- char arraymatrix7[5] = { '6','7','8','9','0' };
- bool encrypt;
- bool newline = true;
- bool isfirst = true;
- int row;
- int col;
- char gear;
- int t = 0;
- string previous;
- char charref;
- string realstring;
- string newstring = "H";
- //enum alphabetlower { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y };
- //enum alphabetupper { A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y };
- void alphamatrix(int matrixrow, int matrixcol)
- {
- // if it is going to decrypt this- then we are going to store it in an string and make them lowercase- so if encrypt is false
- if (encrypt == false) {
- if (matrixcol == 0) {
- realstring += tolower(arraymatrix0[matrixrow]); previous += charref; col = 0; row = 0;
- }
- if (matrixcol == 1) {
- realstring += tolower(arraymatrix1[matrixrow]); previous += charref; col = 0; row = 0;
- }
- if (matrixcol == 2) {
- realstring += tolower(arraymatrix2[matrixrow]); previous += charref; col = 0; row = 0;
- }
- if (matrixcol == 3) {
- realstring += tolower(arraymatrix3[matrixrow]); previous += charref; col = 0; row = 0;
- }
- if (matrixcol == 4) {
- realstring += tolower(arraymatrix4[matrixrow]); previous += charref; col = 0; row = 0;
- }
- if (matrixcol == 5) {
- realstring += " "; previous += charref; col = 0; row = 0;
- }
- if (matrixcol == 6) {
- realstring += tolower(arraymatrix6[matrixrow]); previous += charref; col = 0; row = 0;
- }
- if (matrixcol == 7) {
- realstring += tolower(arraymatrix7[matrixrow]); previous += charref; col = 0; row = 0;
- }
- } // else if it is going to be encrypted - then lowercase the encrypted from variable.
- else {
- // the structure here is look in arrayx[at x] add to encrypted from variable - then reset the rows.
- if (matrixcol == 0) {
- realstring += arraymatrix0[matrixrow]; previous += tolower(charref); col = 0; row = 0;
- }
- if (matrixcol == 1) {
- realstring += arraymatrix1[matrixrow]; previous += tolower(charref); col = 0; row = 0;
- }
- if (matrixcol == 2) {
- realstring += arraymatrix2[matrixrow]; previous += tolower(charref); col = 0; row = 0;
- }
- if (matrixcol == 3) {
- realstring += arraymatrix3[matrixrow]; previous += tolower(charref); col = 0; row = 0;
- }
- if (matrixcol == 4) {
- realstring += arraymatrix4[matrixrow]; previous += tolower(charref); col = 0; row = 0;
- }
- if (matrixcol == 5) {
- realstring += " "; previous += charref; col = 0; row = 0;
- }
- if (matrixcol == 6) {
- realstring += arraymatrix6[matrixrow]; previous += charref; col = 0; row = 0;
- }
- if (matrixcol == 7) {
- realstring += arraymatrix7[matrixrow]; previous += charref; col = 0; row = 0;
- }
- }
- }
- int main()
- {
- //here we are going to define the file that we are trying to stream
- ifstream fileInput;
- fileInput.open("c:\\temp\\New Text Document.txt");
- // start here please if you want to understand this.
- while (!fileInput.eof())
- {
- fileInput >> std::noskipws >> charref;
- // here we make an exception for the first line.
- if (charref == (char)'H' && newline == true) {
- encrypt = true;
- gear = 'D';
- t = 1;
- cout << "Key Encrypted: " << "H";
- }
- // check to see if the line is a new line and wether or not an E and D
- if (charref == (char)'E' && newline == true) {
- encrypt = true;
- gear = 'D';
- t = 1;
- cout << "Encrypted: ";
- }
- if (charref == (char)'D' && newline == true) {
- encrypt = false;
- gear = 'D';
- t = 1;
- cout << "Decrypted: ";
- }
- // this is just to take it out of gear incase the code goes hay wire
- if (isfirst == false && newline == false) { gear = 'N'; }
- // if the line ends and it is a new line then we are going to out put the code
- if (charref == (char)'\n' && newline == false) {
- // at this point my code looks for the first letter of new lines - and so I made it add an H to the begining of the first string before output
- if (previous == "appiness") {
- newstring += previous;
- previous = newstring;
- }
- // were going to output some stuff
- cout << realstring << endl;
- cout << endl << "From: " << previous << endl;;
- cout << endl << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << endl;
- previous = "";
- realstring = "";
- newline = true;
- gear = 'D';
- cout << endl;
- }
- // if its encrypted or not - look through array matrix and pass those array positions to the function - reverse the rows and col variables for decryption.
- if (encrypt == true && newline == false && gear != 'D' || gear != 'D' && encrypt == true && isfirst == true) {
- if (isfirst == true) { isfirst = false; }
- gear = 'N';
- int arraySize = 5;
- charref = toupper(charref);
- char itemToFind = charref;
- for (int i = 0; i < arraySize; i++) {
- if (arraymatrix0[i] == itemToFind) {
- row = 0;
- col = i;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix1[i] == itemToFind) {
- row = 1;
- col = i;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix2[i] == itemToFind) {
- row = 2;
- col = i;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix3[i] == itemToFind) {
- row = 3;
- col = i;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix4[i] == itemToFind) {
- row = 4;
- col = i;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix5[i] == itemToFind) {
- row = 0;
- col = 5;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix6[i] == itemToFind) {
- row = i;
- col = 6;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix7[i] == itemToFind) {
- row = i;
- col = 7;
- alphamatrix(row, col);
- break;
- }
- }
- } //decrypt
- if (encrypt == false && newline == false && gear != 'D' || gear != 'D' && encrypt == false && isfirst == true) {
- if (isfirst == true) { isfirst = false; }
- gear = 'N';
- int arraySize = 5;
- charref = toupper(charref);
- char itemToFind = charref;
- for (int i = 0; i < arraySize; i++) {
- if (arraymatrix0[i] == itemToFind) {
- row = 0;
- col = i;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix1[i] == itemToFind) {
- row = 1;
- col = i;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix2[i] == itemToFind) {
- row = 2;
- col = i;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix3[i] == itemToFind) {
- row = 3;
- col = i;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix4[i] == itemToFind) {
- row = 4;
- col = i;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix5[i] == itemToFind) {
- row = 0;
- col = 5;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix6[i] == itemToFind) {
- row = i;
- col = 6;
- alphamatrix(row, col);
- break;
- }
- if (arraymatrix7[i] == itemToFind) {
- row = i;
- col = 7;
- alphamatrix(row, col);
- break;
- }
- }
- }
- // if this is first - then reset the bool
- if (isfirst == true) { isfirst = false; }
- // if we are in gear and it is a new line - and the t count says that we already chose to encrypt or decrypt then reset t count and set newline bool to false to allow code to go
- if (newline == true && gear == 'D' && t == 1) {
- t = 0;
- newline = false;
- }
- // same thing as above - but allows for gear R as well
- if (newline == true && gear == 'R' && t == 1) {
- t = 0;
- newline = false;
- }
- }
- if (fileInput.eof() == true) {
- cout << realstring;
- cout << endl << "From: " << previous << endl;
- cout << endl << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << endl;
- }
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment