Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<Windows.h>
- #include<fstream>
- #include<string>
- #include<time.h>
- using namespace std;
- char litere[26];
- int ocupat[26], auxi;
- double frecventa[26],frecventa_n[26];
- HANDLE hConsole;
- string plain_t,crypto_t;
- string read_from_file()
- {
- ifstream f("textdecript.txt");
- if (!f.is_open())
- {
- return "EROARE! Fisierul nu exista";
- }
- string text_original, aux;
- while (!f.eof())
- {
- f >> aux;
- text_original += aux;
- }
- f.close();
- return text_original;
- }
- string convert_to_plain(string text_original)
- {
- string plaintext;
- for (unsigned temp = 0; temp < text_original.size(); temp++)
- if(text_original[temp] >= 65 && text_original[temp] <= 90)
- plaintext += text_original[temp];
- else
- if(text_original[temp] >= 97 && text_original[temp] <= 122)
- plaintext += (text_original[temp] - 32);
- return plaintext;
- }
- int esteocupat(int pozitie)
- {
- if( ocupat[pozitie] == 0 )
- {ocupat[pozitie] = 1;
- return 1;}
- else return 0;
- }
- void gener()
- {
- srand(unsigned int (time(NULL)));
- int salt = 26;
- int i = 0;
- while(salt > 0)
- {
- auxi = rand()%26;
- if( esteocupat(auxi) == 1)
- {
- litere[i] = auxi + 65;
- i++;
- salt--;
- }
- }
- }
- string convert(string plaintext)
- {
- string converted;
- for (unsigned temp = 0; temp < plaintext.size(); temp++)
- converted += litere[((int) plaintext[temp]) - 65];
- return converted;
- }
- void frecv(string cryptotext)
- {
- for (unsigned temp = 0; temp < cryptotext.size(); temp++)
- frecventa[cryptotext[temp]-65] += 1;
- }
- void frecv_n(string plaintext)
- {
- for (unsigned temp = 0; temp < plaintext.size(); temp++)
- frecventa_n[plaintext[temp]-65] += 1;
- }
- void afish(string text_a)
- {
- for (unsigned temp = 0; temp < text_a.size(); temp++)
- if(text_a[temp] == 'E')
- {
- SetConsoleTextAttribute(hConsole, 9);
- cout<<text_a[temp];
- }
- else
- {
- SetConsoleTextAttribute(hConsole, 7);
- cout<<text_a[temp];
- }
- }
- void main()
- {
- hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- gener();
- for(int j=0;j<26;j++)
- cout<<"__"<<char(65+j)<<"__ : __"<<litere[j]<<"__"<<endl;
- plain_t = convert_to_plain(read_from_file());
- crypto_t = convert(plain_t);
- cout<<endl<<"================================================="<<endl<<endl<<"PLAIN TEXT:"<<endl<<endl;
- cout<<plain_t<<endl;
- cout<<endl<<"================================================="<<endl<<endl<<"CRYPT TEXT:"<<endl<<endl;
- afish(crypto_t);
- SetConsoleTextAttribute(hConsole, 7);
- frecv(crypto_t);
- frecv_n(plain_t);
- for(int j=0;j<26;j++)
- cout<<"__"<<char(65+j)<<"__ : __"<<frecventa_n[j]/plain_t.size()*100<<"__][ __"<<frecventa[j]/crypto_t.size()*100<<"__"<<endl;
- system("pause");
- }
Add Comment
Please, Sign In to add comment