Jump to content
begood

[c++] Criptare text folosind tabelul lui Vigenere

Recommended Posts

Aici e sursa pentru programul complet : (criptare/decriptare), in sfarsit am promis ceva si am facut, sunt mandru de asta :))


/* Criptare text folosind Tabelul Vigenere */
#include<iostream>
using namespace std;

char a[100][100];
int n=94;

void init(){
int start=33,sf=126,c,i,j;
for(i=0;i<n;i++){
c=start;
for(j=0;j<n;j++){
if(c>sf) c=33;
a[i][j]=c;
c++;
}
start++;
}
}

void criptare(){
char key[1000],text[1000];
int i=0,j=0;

cin.get(); // Fara linia asta face figuri
cout<<"Introduceti cifrul: "; cin.getline(key,999);
cout<<"Introduceti textul de criptat: "; cin.getline(text,999);

/*Cacat estetic*/
cout<<"\n";
for(i=0;text[i]!='\0';i++) cout<<text[i];
cout<<"---";
for(i=0;key[i]!='\0';i++) cout<<key[i];
cout<<"--->";

/* Selectez elementele din tabel */
for(i=0; text[i]!='\0' ;i++){
if(key[j]=='\0') j=0; //in cazul in care cheia este mai scurta decat textul
cout<<a[key[j]-33][text[i]-33];//complicat
j++;
}
}

void decriptare(){
char key[1000],ctext[1000];
int i,j=0,k,m;

cin.get(); //Altfel face figuri
cout<<"Introduceti cifrul: "; cin.getline(key,999);
cout<<"Introduceti textul criptat: "; cin.getline(ctext,999);

for(i=0; ctext[i]!='\0' ;i++){
if(key[j]=='\0') j=0; //lungime_cheie < lungime_text
for(k=0;k<n;k++){
m=key[j]-33;
if(a[k][m] == ctext[i])
cout<<a[k][0];
}
j++;
}
}

int main(){
int opt;

init(); //initializez tabelul

cout<<"Vrei sa : "<<endl<<"1)Criptezi text"<<endl<<"2)Decriptezi text"<<endl;
cout<<">";cin>>opt;

switch (opt){
case (1) : {
criptare();
break;}
case (2) : {
decriptare();
break;}
default : {
cout<<"Ai de ales intre 1 si 2, e asa greu? ";
break;}
}
return 0;
}

*Tocmai am vazut ca in tabel n-am spatiu, si nici cacatu' estetic pentru decriptare (se putea sa nu-mi scape ceva...? ) Revin cu un edit *

-- Inca odata apelez la astia mai cu experienta. Va trece prin cap vreo metoda prin care pot sa reprezint asezarea a 94 de caractere (printr-un numar sau ceva care poate fi memorat de-un om), ca sa pot sa fac tabelul variabil? --

Edited by Patrunjel
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...