1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
// Algorithm.cpp : main project file.
#include "stdafx.h" // Using MS Visual C++ 2008 Express - Remove if not needed
#include <iostream>
#include <string>
#include <conio.h>
#include <windows.h>
using namespace std;
using namespace System;
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;
void WaitKey();
void gotoXY(int x, int y);
void gotoXY(int x, int y, string text);
int main()
{
int width = 115, height = 38, row, xamount=1, len;
Console::SetWindowSize(width, height );
char Letters[26][26], temp;
char Text[80];
string erase(80,' ');
int x, y, z;
for(y=0;y<26;y++)
{
for(x=0;x<26;x++)
{
Letters[y][x] = 'A'+x;
}
}
cout << endl << endl;
cout << " ";
for (y=0;y<26;y++)
{
cout << y+1 << " ";
if(y<9)
cout << " ";
}
cout << endl;
row = 1;
do
{
for(x=0;x<xamount;x++)
{
temp = Letters[row][0];
for(z=0;z<26;z++)
{
Letters[row][z] = Letters[row][z+1];
}
Letters[row][25] = temp;
}
row++;
xamount=(row)+xamount;
} while(row<26);
for (y=0;y<26;y++)
{
if (y<9)
cout << " ";
cout << " " << y+1 << " ";
for(x=0;x<26;x++)
{
cout << "[" << Letters[y][x] << "] ";
}
if (y>16)
cout << " ";
cout << 26-y << endl;
}
cout << " ";
for (y=26;y>0;y--)
{
cout << y << " ";
if(y<=9)
cout << " ";
}
do
{
gotoXY(46,30,"Type 'Exit' to quit or");
gotoXY(38,31,": Please enter a sentence to encrypt :");
gotoXY(5,33);
cin.getline(Text, 80);
len=0;
int next = 0;
for(x=0;x<80;x++)
if (Text[x]!='\0')
{
len++;
Text[x]=toupper(Text[x]);
}
else
break;
gotoXY(5,33,erase);
gotoXY((115-len)/2,33,Text);
gotoXY((115-len)/2,34);
for(x=0;x<len;x++)
{
for(y=0;y<26;y++)
{
if(Text[x]== Letters[next][y])
{
cout << Letters[25-next][25-y];
}
}
if(Text[x]>='A' && Text[x]<='Z')
{
next++;
if (next>25)
next=0;
}
if(Text[x]<'A' || Text[x]>'Z')
cout << Text[x];
}
WaitKey();
for(x=33;x<37;x++)
gotoXY(5,x,erase);
} while(Text[0] != 'E' && Text[1] != 'X' && Text[2] != 'I' && Text[3] != 'T');
gotoXY(44,36);
return 0;
}
void WaitKey()
{
gotoXY(43,36,"Press any key to continue...");
while (_kbhit()) _getch(); // Empty the input buffer
_getch(); // Wait for a key
while (_kbhit()) _getch(); // Empty the input buffer (some keys sends two messages)
}
void gotoXY(int x, int y)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console,CursorPosition);
}
void gotoXY(int x, int y, string text)
{
CursorPosition.X = x;
CursorPosition.Y = y;
SetConsoleCursorPosition(console,CursorPosition);
cout << text;
}
|