Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- string keyWord_In_Array(string keyword) {
- string code;
- char ch = ' ';
- for (size_t i = 0; i < keyword.length() ; i++)
- {
- if (keyword[i] != ch) {
- code += keyword[i];
- ch = keyword[i];
- }
- }
- return code;
- }
- string Make_Rest_Code(string code) {
- string fullCode = "ABCDEFGHIJKLMNOPQRSTUVWXY";
- for (size_t i = 0; i < code.length() ; i++)
- {
- int index = 0;
- index = fullCode.find(code[i]);
- fullCode.erase(index, 1);
- }
- return fullCode;
- }
- char Decrypt_Character(char ch, char chart[5][5]) {
- char convertValue = ' ';
- for (size_t i = 0; i < 5; i++)
- {
- for (size_t j = 0; j < 5; j++) {
- if (ch == chart[i][j]) {
- convertValue = chart[j][i];
- }
- else {
- convertValue = ch;
- }
- }
- }
- convertValue = tolower(convertValue);
- return convertValue;
- }
- char Encrypt_Character(char ch, char chart[5][5]) {
- char convertValue = ' ';
- for (size_t i = 0; i < 5; i++)
- {
- for (size_t j = 0; j < 5; j++) {
- if (ch == chart[i][j]) {
- convertValue = chart[j][i];
- }
- else {
- convertValue = ch;
- }
- }
- }
- convertValue = toupper(convertValue);
- return convertValue;
- }
- int main()
- {
- string data;
- string code;
- string restCode;
- int count1 = 0;
- int count2 = 0;
- char chart[5][5];
- ifstream inputFile;
- inputFile.open("c:\\temp\\mp5.txt");
- getline(inputFile, data);
- cout << "Keyword is " << data << endl;
- code = keyWord_In_Array(data);
- restCode = Make_Rest_Code(code);
- cout << restCode;
- for (size_t i = 0; i < size(chart) ; i++)
- {
- for (size_t j = 0; j < size(chart[i]); j++)
- {
- if (count1 < code.length()) {
- chart[i][j] = code[count1];
- count1++;
- }
- else {
- chart[i][j] = restCode[count2];
- count2++;
- }
- }
- }
- cout << endl << endl;
- cout << " Col 0 Col 1 Col 2 Col 3 Col 4" << endl;
- cout << " __________________________________" << endl;
- for (size_t i = 0; i < size(chart); i++)
- {
- printf("Row %d:", i);
- for (size_t j = 0; j < size(chart[i]); j++)
- {
- cout << " | ";
- printf("%c ", chart[i][j]);
- }
- cout << " |\n";
- }
- cout << "******************************************" << endl;
- while (!inputFile.eof()) {
- getline(inputFile, data);
- cout << data << endl;
- string convertString = "";
- if (data[0] == 'D') {
- for (size_t i = 2; i < data.size() ; i++)
- {
- char convertValue = ' ';
- for (size_t j = 0; j < size(chart); j++)
- {
- for (size_t k = 0; k < size(chart[j]); k++) {
- if (data[i] == chart[j][k]) {
- convertValue = chart[k][j];
- }
- else {
- convertValue = data[i];
- cout << data[i] << endl;
- }
- }
- }
- convertValue = tolower(convertValue);
- convertString += convertValue;
- }
- cout << "Decrypt to: " << endl;
- cout << convertString << endl;
- cout << "******************************************" << endl;
- }
- else if (data[0] == 'E') {
- for (size_t i = 2; i < data.size(); i++)
- {
- char convertValue = ' ';
- for (size_t j = 0; j < size(chart); j++)
- {
- for (size_t k = 0; k < size(chart[j]); k++) {
- if (data[i] == chart[j][k]) {
- convertValue = chart[k][j];
- }
- else {
- convertValue = data[i];
- }
- }
- }
- convertValue = toupper(convertValue);
- convertString += convertValue;
- }
- cout << "Encrypt to: " << endl;
- cout << convertString << endl;
- cout << "******************************************" << endl;
- }
- }
- cout << "Have fun!!" << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment