out_of_theblue10

crypt

May 20th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. using namespace std;
  4. int i,j,key,m,n,c,p;
  5. string s;
  6. int main()
  7. {
  8. ifstream fi("crypt.in");
  9. ofstream fo("crypt.out");
  10. fi>>n;
  11. getline(fi,s);
  12. for(i=1;i<=n;i++)
  13. {
  14. getline(fi,s);
  15. m=s.length();
  16. key=0;
  17. for(j=2;j<=m;j++) key+=j;
  18. for(j=0;j<m;j++)
  19. {
  20. c=(int)s[j];
  21. if(c%8==1)//Grija la cele lungi
  22. {
  23. if((j%8==0) or(j%8==1)) p=0;
  24. if((j%8==2) or(j%8==3)) p=4;
  25. if((j%8==4) or(j%8==5)) p=8;
  26. if((j%8==6) or(j%8==7)) p=12;
  27. fo<<(char)(c-key+p);
  28. }
  29. if(c%8==2)
  30. {
  31. p=j/4;
  32. p*=8;
  33. if(j%2) p+=2;
  34. fo<<(char)(c-key+p);
  35. }
  36. if(c%8==3)
  37. {
  38. p=j/4;
  39. p*=8;
  40. fo<<(char)(c-key+p);
  41. }
  42. if(c%8==4)//Grija la cele lungi
  43. {
  44. p=j/8;
  45. p*=16;
  46. if(j%4==1) p+=2;
  47. if(j%4==2) p+=4;
  48. if(j%4==3) p+=6;
  49. fo<<(char)(c-key+p);
  50. }
  51. if(c%8==5)//Grija la cele lungi
  52. {
  53. p=j/8;
  54. p*=16;
  55. if((j%4==2) or(j%4==3)) p+=4;
  56. fo<<(char)(c-key+p);
  57. }
  58. if(c%8==6)
  59. {
  60. p=0;
  61. if(j%2) p=2;
  62. fo<<(char)(c-key+p);
  63. }
  64. if(c%8==7)
  65. {
  66. fo<<(char)(c-key);
  67. }
  68. if(c%8==0)
  69. {
  70. p=j*2;
  71. fo<<(char)(c-key+p);
  72. }
  73. }
  74. fo<<"\n";
  75. }
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment