Zaloguj się

View Full Version : C++ funkcja odszyfrowuj?ca.



Myst
07-06-2011, 21:10
Siemka mam taką funkcję szyfrującą


string szyfruj (string tekst)
{
string wynik;
int dl=tekst.size();
for (int i=0;i<dl;i+=4) wynik+=tekst[i];
for (int i=1;i<dl;i+=2) wynik+=tekst[i];
for (int i=2;i<dl;i+=4) wynik+=tekst[i];
return wynik;
}

i muszę do tego dorobić funkcję odszyfrowująca jakiś tekst ;/, ale nie mam pojęcia jak to zrobić. Czy może ktoś z Was wie jak to zrobić?

Gogeta SsJ2
10-06-2011, 17:55
Polecam forum informatyczne .

Xelix
10-06-2011, 22:25
Mi tam to się w ogóle nie chcę skompilować w devie.

party starter
11-06-2011, 11:24
nie chcialo mi sie robic odzielnych funcji, wjebalem wszystko w main

czymaj :


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{string tekst;
int a; int p;
int b; int c;
a=0;b=0;c=0;
cin>>tekst;
string wynik;
int dl=tekst.size();
for (int i=0;i<dl;i+=4) wynik+=tekst[i],a++;
for (int i=1;i<dl;i+=2) wynik+=tekst[i],b++;
for (int i=2;i<dl;i+=4) wynik+=tekst[i],c++;
cout<<wynik<<" ";
string t;
p=0;
string u; u='a';
do {t+=u;} while (t.size()<a+b+c);

for(int h=0;h<a;h++) t[p]=wynik[h],p=p+4;
p=1;
for(int h=a;h<a+b;h++) t[p]=wynik[h],p=p+2;
p=2;
for(int h=a+b;h<a+b+c;h++) t[p]=wynik[h],p=p+4;

cout<<t<<" ";



cout<<"koniec";
system("PAUSE");
return EXIT_SUCCESS;
}