Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cstring>
- using namespace std;
- int i,j,key,m,n,c,p;
- string s;
- int main()
- {
- ifstream fi("crypt.in");
- ofstream fo("crypt.out");
- fi>>n;
- getline(fi,s);
- for(i=1;i<=n;i++)
- {
- getline(fi,s);
- m=s.length();
- key=0;
- for(j=2;j<=m;j++) key+=j;
- for(j=0;j<m;j++)
- {
- c=(int)s[j];
- if(c%8==1)//Grija la cele lungi
- {
- if((j%8==0) or(j%8==1)) p=0;
- if((j%8==2) or(j%8==3)) p=4;
- if((j%8==4) or(j%8==5)) p=8;
- if((j%8==6) or(j%8==7)) p=12;
- fo<<(char)(c-key+p);
- }
- if(c%8==2)
- {
- p=j/4;
- p*=8;
- if(j%2) p+=2;
- fo<<(char)(c-key+p);
- }
- if(c%8==3)
- {
- p=j/4;
- p*=8;
- fo<<(char)(c-key+p);
- }
- if(c%8==4)//Grija la cele lungi
- {
- p=j/8;
- p*=16;
- if(j%4==1) p+=2;
- if(j%4==2) p+=4;
- if(j%4==3) p+=6;
- fo<<(char)(c-key+p);
- }
- if(c%8==5)//Grija la cele lungi
- {
- p=j/8;
- p*=16;
- if((j%4==2) or(j%4==3)) p+=4;
- fo<<(char)(c-key+p);
- }
- if(c%8==6)
- {
- p=0;
- if(j%2) p=2;
- fo<<(char)(c-key+p);
- }
- if(c%8==7)
- {
- fo<<(char)(c-key);
- }
- if(c%8==0)
- {
- p=j*2;
- fo<<(char)(c-key+p);
- }
- }
- fo<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment