Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cstring>
- using namespace std;
- int main()
- {
- char s[1000010];
- int c,m;
- ifstream f("scytale.in");
- f>>c>>s>>m;
- f.close();
- int n=(int)strlen(s);
- char A[m+m+1][n+m+1];
- for(int i=0;i<=m+m;++i)
- for(int j=0;j<=n+m;++j)
- A[i][j]='.';
- int k=0;
- ofstream g("scytale.out");
- if(s[0]<'A'||s[0]>'Z')
- {
- g.close();
- return 0;
- }
- if(c==1) /// Criptarea
- {
- for(int i=1;i<=m;++i) /// Formez matricea
- for(int j=i;j<=n;j+=m)
- A[i][j]=s[k++];
- for(int j=1;j<=n;) /// Afisez mesajul criptat
- for(int i=1;i<=m&&j<=n;++i,++j)
- if(A[i][j]!='.')
- g<<A[i][j];
- }
- else /// Decriptarea
- {
- for(int j=1;j<=n;) /// Formez matricea
- for(int i=1;i<=m;++i,++j)
- A[i][j]=s[k++];
- for(int i=1;i<=m;++i) /// Afisez mesajul decriptat
- for(int j=1;j<=n;++j)
- if(A[i][j]!='.')
- g<<A[i][j];
- }
- g<<'\n';
- g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement