Wybierz plik:




  • Opis programu "szyfr_vinegerea":

    Brak opisu



    #include <iostream>
    #include <fstream>
    #include <string>
    #include <iomanip>
    using namespace std;
    void zad1(string tekst)
    {
    string klucz[12]={"L","U","B","I","M","Y","C","Z","Y","T","A","C"};
    int pomin=0;
    int licznik=0;
    cout<<tekst<<endl;
    for(int i=0;i<tekst.length();i++)
    {

    if(tekst[i]==' ' || tekst[i]=='.' || tekst[i]==',')
    {
    pomin++;
    }
    else
    {

    if((i-pomin)%12==0) licznik++;

    if(((int(tekst[i])-'A')+(int(klucz[(i-pomin)%12][0])-'A'))<26)
    {

    if((int(tekst[i])-'A'+int(klucz[(i-pomin)%12][0]))-'A'>0)
    {
    tekst[i]=char(int(tekst[i])-'A'+int(klucz[(i-pomin)%12][0]));
    }
    }
    else
    {
    tekst[i]=char((int(tekst[i])-'A'+int(klucz[(i-pomin)%12][0]))-26);
    }
    }
    }
    cout<<tekst<<" "<<licznik<<endl;
    }
    void zad2(string tekst)
    {
    string klucz[13]={"Z","L","O","D","Z","I","E","J","C","Z","A","S","U"};
    int pomin=0;
    cout<<tekst<<endl;
    for(int i=0;i<tekst.length();i++)
    {

    if(tekst[i]==' ' || tekst[i]=='.' || tekst[i]==',')
    {
    pomin++;
    }
    else
    {

    if(((int(tekst[i])-'A')-(int(klucz[(i-pomin)%13][0])-'A'))>=0)
    {
    tekst[i]=char(int(tekst[i])+'A'-int(klucz[(i-pomin)%13][0]));
    }
    else
    {
    tekst[i]=char((int(tekst[i])+'A'-int(klucz[(i-pomin)%13][0]))+26);
    }
    }
    }
    cout<<tekst<<endl;
    }
    void zad3(string tekst)
    {
    double tab[26]={0};
    double ilosc=0;
    double ko=0;
    double d=0;
    for(int i=0; i<tekst.length(); i++)
    {

    if(tekst[i]==' ' || tekst[i]=='.' || tekst[i]==',')
    {
    }
    else
    {
    tab[int(tekst[i])-'A']++;
    ilosc++;
    }
    }
    for(int j=0; j<26; j++)
    {
    ko=ko+(tab[j]*(tab[j]-1));
    }
    ko=ko/(ilosc*(ilosc-1));
    d=0.0285/(ko-0.0385);
    cout<<"13 "<<fixed<<setprecision(2.0)<<d;
    }
    int main()
    {
    fstream wejscie1;
    wejscie1.open("dokad.txt",ios::in);
    string tekst="";

    if(wejscie1.good())
    {
    getline(wejscie1,tekst);
    //zad1(tekst);
    }
    else
    {
    cout<<"dasads";
    }
    wejscie1.close();
    fstream wejscie2;
    wejscie2.open("szyfr.txt",ios::in);
    string tekst2="";

    if(wejscie2.good())
    {
    getline(wejscie2,tekst2);
    zad2(tekst2);
    //zad3(tekst2);
    }
    else
    {
    cout<<"dasads";
    }
    wejscie2.close();
    return 0;
    }