Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <fstream>
- using namespace std;
- void usuwanie_powtorzen_kodu(string &klucz)
- {
- string kod2;
- int temp;
- for(int i = 0; i < klucz.length(); i++)
- {
- if(klucz[i]>=65 && klucz[i]<=90)
- klucz[i]+=32;
- }
- for(int i = 0; i < klucz.length(); i++)
- {
- temp = 0;
- for(int j = 0; j < i; j++)
- {
- if(klucz[i] == klucz[j])
- {
- temp++;
- }
- }
- if(temp==0)
- kod2+=klucz[i];
- }
- klucz=kod2;
- }
- void wczytaj_teksty(string &klucz, string &tekst)
- {
- fstream tekstj, klu;
- tekstj.open("jawny.txt", ios::in);
- if(tekstj.is_open())
- {
- while(tekstj)
- {
- getline(tekstj, tekst);
- }
- tekstj.close();
- }
- klu.open("klucz.txt", ios::in);
- if(klu.is_open())
- {
- while(klu)
- {
- getline(klu, klucz);
- }
- tekstj.close();
- }
- }
- void tworzenie_alfabetu(string klucz, string &alfabet, string &aj)
- {
- int temp;
- for(int i=0 ; i<klucz.length(); i++)
- {
- alfabet+=klucz[i];
- }
- for(int i='a'; i<='z'; i++)
- {
- temp=0;
- for(int j= 0; j<alfabet.length();j++)
- {
- if(char(i)==alfabet[j])
- temp++;
- }
- if(temp==0)
- alfabet+=char(i);
- }
- for(int i='a';i<='z';i++)
- {
- aj+=char(i);
- }
- }
- void szyfrowanie(string klucz,string alfabet,string tekst,string &szyfr)
- {
- for(int i = 0; i<tekst.length(); i++)
- {
- if(tekst[i]!=' ')
- {
- if(tekst[i]>=97 && tekst[i]<=122)
- szyfr+=alfabet[int(tekst[i])-97];
- else
- szyfr+=char(alfabet[int(tekst[i])-65]-32);
- }
- //else
- //szyfr+=tekst[i];
- }
- cout <<"\nKryptogram podanego tekstu: "<< szyfr;
- fstream zap;
- zap.open("kryptogram.txt", ios::out);
- if(zap.is_open())
- {
- zap << szyfr;
- zap.close();
- }
- }
- void wyswietl_alfabety(string alfabet, string aj)
- {
- cout <<"\n\n M: ";
- for(int i=0; i<alfabet.length(); i++)
- {
- cout <<" "<< alfabet[i];
- }
- cout <<"\n D: ";
- for(int i=0; i<alfabet.length(); i++)
- {
- cout <<" "<< char(int(alfabet[i])-32);
- }
- cout <<"\n A: ";
- for(int i=0; i<alfabet.length(); i++)
- {
- cout <<" "<< aj[i];
- }
- }
- main()
- {
- string tekst, klucz, alfabet,szyfr,aj;
- wczytaj_teksty(klucz,tekst);
- usuwanie_powtorzen_kodu(klucz);
- tworzenie_alfabetu(klucz, alfabet, aj);
- szyfrowanie(klucz, alfabet, tekst, szyfr);
- wyswietl_alfabety(alfabet, aj);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement