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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
#include <iostream>
# include <cstring>
# include <cstdlib>
# include <conio.h>
# include <stdio.h>
# include <cmath>
# define Decriptare_Caesar '1'
# define Cript_Matrice '2'
# define Iesire '3'
using namespace std;
void Decript_Caes ();
void Cript_Matr ();
int pp_matr(int x) ;
int main()
{
char r ;
for(;;)
{
system("CLS") ;
cout << endl ; cout << endl ; cout << endl ; cout << endl ; cout << endl ;
cout << " 1. Decriptare Caesar. " << endl ;
cout << " 2. Criptare prin transpozitie cu matrici. " << endl ;
cout << " 3. Iesire. " << endl ;
cout << endl ;
cout << " Optiune: " ;
system("color 0");
for(;;)
{
r = getch() ;
if(r==Decriptare_Caesar||r==Cript_Matrice||r==Iesire)
break;
}
if(r==Decriptare_Caesar)
{
Decript_Caes() ;
cout << endl ;
cout << " Apasati o tasta pentru a reveni la meniu." ;
getch() ;
}
else if(r==Cript_Matrice)
{
Cript_Matr() ;
cout << endl ;
cout << " Apasati o tasta pentru a reveni la meniu." ;
getch() ;
}
else if(r==Iesire)
break;
}
return 0;
}
void Decript_Caes(char text[100])
{
int i, mar ; char textx[100] ;
mar = strlen(text) ;
for(i=0;i<mar;i++)
if(text[i]==' ') textx[i] = text[i] ;
else
if(((text[i]>'c')&&(text[i]<='z'))||((text[i]>'C')&&(text[i]<='Z'))) textx[i] = text[i] - 3 ;
else
{
if(text[i]=='a') textx[i] = 'x' ;
if(text[i]=='b') textx[i] = 'y' ;
if(text[i]=='c') textx[i] = 'z' ;
if(text[i]=='A') textx[i] = 'X' ;
if(text[i]=='B') textx[i] = 'Y' ;
if(text[i]=='C') textx[i] = 'Z' ;
}
textx[mar] = '\0' ;
cout << endl ;
cout << " Textul decriptat este: "<< textx ;
}
void Cript_Transp()
{
int i, j, mar, nrcol, lit = 0 ;
char text[100] ;
cout << " Introduceti sirul: " ;
cin.getline(text,100) ;
char textx[100], matr[2][50] ;
mar = strlen(text) ;
if(mar%2==0) nrcol = mar/2 ;
else nrcol = mar/2 + 1 ;
for(i=0;i<2;i++)
for(j=0;j<nrcol;j++)
{
if(i==0) matr[i][j] = text[j];
else matr[i][j] = text[i+j+nrcol-1] ;
}
for(j=0;j<nrcol;j++)
for(i=0;i<2;i++)
{
textx[lit] = matr[i][j] ;
lit++;
}
textx[lit] = '\0' ;
cout << endl ;
cout << " Textul criptat este: "<< textx;
}
void Cript_Matr()
{
int mar, marr, i, j, k=0 ;
char textx[100],matr[10][10],matr2[10][10],text[100] ;
cout<<"Introduceti textul: ";
cin.getline(text,100);
mar = strlen(text) ;
if(!pp_matr(mar)) marr = sqrt(mar) + 1 ;
else marr = sqrt(mar) ;
for(i=1;i<=marr;i++)
for(j=1;j<=marr;j++)
{
matr[i][j] = text[k] ;
k++ ;
}
for(j=1;j<=marr;j++)
for(i=1;i<=marr;i++)
matr2[j][i] = matr[i][j];
k = 0 ;
for(i=1;i<=marr;i++)
for(j=1;j<=marr;j++)
{
textx[k] = matr2[i][j] ;
if(k<mar) k++;
}
textx[k] = '\0' ;
cout << endl ;
cout << " Textul criptat este : " << textx ;
}
int gasit_col_mans(char x, int matr[5][5])
{
int i, j, ok=1, col ;
for(i=0;(i<5)&&ok;i++)
for(j=0;(j<5)&&ok;j++)
if(int(x)==(matr[i][j]+32))
{
ok = 0 ;
col = j ;
}
return col ;
}
int gasit_lin_mans(char x, int matr[5][5])
{
int i, j, ok=1, lin ;
for(i=0;(i<5)&&ok;i++)
for(j=0;(j<5)&&ok;j++)
if(int(x)==(matr[i][j]+32))
{
ok = 0 ;
lin = i ;
}
return lin ;
}
int pp_matr(int x)
{
int i ;
for(i=2;(i<=x);i++)
if((x%i==0)&&((x/i)%i==0)) return 1 ;
return 0 ;
}
|