Heja, może napiszę od razu że jestem zielony w programowaniu.... Otóż mam napisać program do kodowania i odkodowywania podawanego hasła. Mam tu kilka problemów... ponieważ przez jedną funkcję koduję a przez drugą rozkodowuję to samo hasło i nie chcę żeby użytkownik wpisywał hasło przy wybraniu opcji 2. a nie umiem umieścić w funkcji rozkodowywującej tablicy z hashem(zmiennej) z funkcji kodującej.... any ideas?
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
using namespace std;
const int S=300;
const int Q=500;
int liczba;
wchar_t tab[]=
{
'?','/','.','>','<',',','M','N','B','V',
'C','X','Z','A','S','D','F','G','H','J',
'K','L',';',':','"','|',']','}','{','[',
'P','O','I','U','Y','T','R','E','W','Q',
'+','=','-','_','0',')','(','9','*','8',
'%','5','4','$','3','#','@','2','!','1',
'~','`','q','w','e','r','t','y','u','i',
'o','p','a','s','d','f','g','h','j','k',
'l','z','x','c','v','b','n','m','&','7',
'6','^',
};
typedef struct{
wchar_t tab[S]; //moze byc tez char
int dl;
string p;
}struktura;
struktura strpassword()
{
struktura strpassword;
cout<<"\nPlease enter your password: ";
cin>>strpassword.p;
return strpassword;
}
struktura encryptor(struktura strpassword)
{
struktura nowatab;
for(int i=0;i<strpassword.p.length();i++)
nowatab.tab[i]=0;
for(int j=0; j<strpassword.p.length();j++)
for(int i=0;i<92;i++)
if(strpassword.p[j]==tab[i])
nowatab.tab[j]=i;//kodowanie hasla
for(int d=0;d<strpassword.p.length();d++)
cout<<nowatab.tab[d]<<",";
cout<<endl; //wyswietlanie nowataba
return nowatab;
/*FILE *plik = fopen("hashbejbi.txt", "w");//w - oznacza, że //otwieramy plik do zapisu.
for(int i = 0; i < strpassword.length(); i++)
{
fprintf(plik, "%d ", nowatab[i]);
}
fclose(plik);
*/
}
struktura decryptor(struktura password)
{
for(int i=0;i<password.p.length();i++)
cout<<password.p;
struktura nowanowatab;
for(int j=0;j<5;j++)
for(int i=0;i<92;i++)
if(password.tab[j]==i)
nowanowatab.tab[j]=tab[i];
for(int i=0;i<5;i++)
cout<<nowanowatab.tab[i];
return 0;
};
int main()
{
cout<<" ### PASSWORD ENCRYPTOR(1) ### "<<endl;
cout<<" ### HASH DECRYPTOR(2) ### "<<endl;
cout<<" ### SEEK & FIND (3) ### "<<endl;
cout<<" ### EXIT(0) ### "<<endl;
cin>>liczba;
switch(liczba)
{
case 1:
{
system("CLS");
cout<<"### PASSWORD ENCRYPTOR ###\n\n"<<endl;
cout<<"initializing encryption stream # .......\n"<<endl;
system("PAUSE");
encryptor(strpassword());
}
case 2:
{
cout<<"### PASSWORD DECRYPTOR ###\n\n";
decryptor(encryptor(strpassword()));
system("PAUSE");
system("CLS");
}
case 0: break;
default: cout<<"jeszcze raz..."<<endl;
}
return 0;
}