Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<windows.h>
  4. #include<locale.h>
  5. #include<time.h>
  6.  
  7. void shiftAll(char text[20000],int len,int c,char dir)
  8. {
  9. if(dir == '+')
  10. {
  11. for(int i = 0;i<len;i++)
  12. {
  13. text[i] = text[i] + c;
  14. }
  15. }
  16. else if(dir == '-')
  17. {
  18. for(int i = 0;i<len;i++)
  19. {
  20. text[i] = text[i] - c;
  21. }
  22. }
  23. }
  24.  
  25. int trueChar(char c)
  26. {
  27. if((c<224) || (c>255)) return 0;
  28. else return 1;
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34. srand(time(0));
  35. setlocale(0, "");
  36. char text[20000];
  37. char text2[20000];
  38.  
  39. FILE* f = fopen("TextRus.txt","r");
  40. FILE* g = fopen("TextRus1.txt","w");
  41. int len = 0;
  42. while(fscanf(f,"%c",&text[len++]) != EOF);
  43. len--;
  44. for(int i = 0;i<len;i++)
  45. {
  46. printf("%c",text[i]);
  47. }
  48. int shift = rand()%255 + 1;
  49. for(int i = 0;i<len;i++)
  50. {
  51. fprintf(g,"%c",text[i]+shift);
  52. text2[i] = text[i]+shift;
  53. }
  54.  
  55. fclose(f);
  56. fclose(g);
  57.  
  58. printf("\n");
  59. g = fopen("TextRus1.txt","r");
  60. int sh = 1;
  61.  
  62. for(int i = 0;i<len;i++)
  63. {
  64. printf("%c",text2[i]);
  65. }
  66.  
  67. int k = 0;
  68.  
  69.  
  70. for(sh = 1;sh <= 255;sh++)
  71. {
  72. k = 0;
  73. shiftAll(text2,len,sh,'+');
  74. for(int i = 0;i<len;i++)
  75. {
  76. if(trueChar(text2[i]) == 1)
  77. k++;
  78. }
  79. if(k == len) break;
  80. else shiftAll(text2,len,sh,'-');
  81. }
  82.  
  83. if(sh <=255)
  84. {
  85. for(int i = 0;i<len;i++)
  86. {
  87. printf("%c",text2[i]);
  88. }
  89. }
  90. else printf("ne udalos");
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. //while(fscanf(g,"%c",&sh) != EOF){printf("%c",sh);}
  99. fclose(g);
  100.  
  101. //while(())
  102. /*for(int i = 0;i<=255;i++)
  103. {
  104. printf("%c - %i\n",(char)i,i);
  105. }*/
  106.  
  107.  
  108. system("pause>0");
  109. return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement