Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include <string.h>
- #include <conio.h>
- #include <cstdlib>
- class string
- {
- public:
- char a,b;
- };
- int main()
- {
- char str_src[100],str_dest[150],string_temp[150],*choice;
- string str_mat[9][9];
- int i,order,j,k,m,c,len;
- fflush(stdin);
- gets(choice);
- if(strcmp(choice,"ENCODE")==0)
- {
- fflush(stdin);
- cin.getline(str_src,100);
- len=strlen(str_src);
- order=1;
- while(order*order<(len+1)/2)
- order+=2;
- for(i=len;i<order*order*2;i++)
- str_src[i]='/';
- str_src[i]=0;
- k=0;
- for(i=0;i<order;i++)
- for(j=0;j<order;j++)
- {
- str_mat[i][j].a=str_src[k];
- str_mat[i][j].b=str_src[k+1];
- k+=2;
- }
- str_dest[0]=str_mat[order/2][order/2].a;
- str_dest[1]=str_mat[order/2][order/2].b;
- i=order/2;
- m;
- j=order/2;
- k=2;
- c=1;
- while(c<order)
- {
- for(m=1;m<=c;m++)
- {
- j--;
- str_dest[k]=str_mat[i][j].a;
- str_dest[k+1]=str_mat[i][j].b;
- k+=2;
- }
- for(m=1;m<=c;m++)
- {
- i--;
- str_dest[k]=str_mat[i][j].a;
- str_dest[k+1]=str_mat[i][j].b;
- k+=2;
- }
- c++;
- for(m=1;m<=c;m++)
- {
- j++;
- str_dest[k]=str_mat[i][j].a;
- str_dest[k+1]=str_mat[i][j].b;
- k+=2;
- }
- for(m=1;m<=c;m++)
- {
- i++;
- str_dest[k]=str_mat[i][j].a;
- str_dest[k+1]=str_mat[i][j].b;
- k+=2;
- }
- c++;
- }
- for(m=1;m<order;m++)
- {
- j--;
- str_dest[k]=str_mat[i][j].a;
- str_dest[k+1]=str_mat[i][j].b;
- k+=2;
- }
- str_dest[order*order*2]=0;
- cout<<endl<<str_dest;
- }
- else if(strcmp(choice,"DECODE")==0)
- {
- fflush(stdin);
- cin.getline(str_dest,150);
- //strcpy(str_dest,string_temp);
- len=strlen(str_dest);
- order=1;
- while((order*order)<len/2)
- order+=2;
- str_mat[order/2][order/2].a=str_dest[0];
- str_mat[order/2][order/2].b=str_dest[1];
- i=order/2;
- m;
- j=order/2;
- k=2;
- c=1;
- while(c<order)
- {
- for(m=1;m<=c;m++)
- {
- j--;
- str_mat[i][j].a=str_dest[k];
- str_mat[i][j].b=str_dest[k+1];
- k+=2;
- }
- for(m=1;m<=c;m++)
- {
- i--;
- str_mat[i][j].a=str_dest[k];
- str_mat[i][j].b=str_dest[k+1];
- k+=2;
- }
- c++;
- for(m=1;m<=c;m++)
- {
- j++;
- str_mat[i][j].a=str_dest[k];
- str_mat[i][j].b=str_dest[k+1];
- k+=2;
- }
- for(m=1;m<=c;m++)
- {
- i++;
- str_mat[i][j].a=str_dest[k];
- str_mat[i][j].b=str_dest[k+1];
- k+=2;
- }
- c++;
- }
- for(m=1;m<order;m++)
- {
- j--;
- str_mat[i][j].a=str_dest[k];
- str_mat[i][j].b=str_dest[k+1];
- k+=2;
- }
- k=0;
- for(i=0;i<order;i++)
- for(j=0;j<order;j++)
- {
- if(str_mat[i][j].a!='/')
- {
- str_src[k]=str_mat[i][j].a;
- k++;
- }
- if(str_mat[i][j].b!='/')
- {
- str_src[k]=str_mat[i][j].b;
- k++;
- }
- }
- str_src[k]=0;
- cout<<endl<<str_src;
- }
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement