Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- #include<windows.h>
- #include<locale.h>
- #include<time.h>
- void shiftAll(char text[20000],int len,int c,char dir)
- {
- if(dir == '+')
- {
- for(int i = 0;i<len;i++)
- {
- text[i] = text[i] + c;
- }
- }
- else if(dir == '-')
- {
- for(int i = 0;i<len;i++)
- {
- text[i] = text[i] - c;
- }
- }
- }
- int trueChar(char c)
- {
- if((c<224) || (c>255)) return 0;
- else return 1;
- }
- int main()
- {
- srand(time(0));
- setlocale(0, "");
- char text[20000];
- char text2[20000];
- FILE* f = fopen("TextRus.txt","r");
- FILE* g = fopen("TextRus1.txt","w");
- int len = 0;
- while(fscanf(f,"%c",&text[len++]) != EOF);
- len--;
- for(int i = 0;i<len;i++)
- {
- printf("%c",text[i]);
- }
- int shift = rand()%255 + 1;
- for(int i = 0;i<len;i++)
- {
- fprintf(g,"%c",text[i]+shift);
- text2[i] = text[i]+shift;
- }
- fclose(f);
- fclose(g);
- printf("\n");
- g = fopen("TextRus1.txt","r");
- int sh = 1;
- for(int i = 0;i<len;i++)
- {
- printf("%c",text2[i]);
- }
- int k = 0;
- for(sh = 1;sh <= 255;sh++)
- {
- k = 0;
- shiftAll(text2,len,sh,'+');
- for(int i = 0;i<len;i++)
- {
- if(trueChar(text2[i]) == 1)
- k++;
- }
- if(k == len) break;
- else shiftAll(text2,len,sh,'-');
- }
- if(sh <=255)
- {
- for(int i = 0;i<len;i++)
- {
- printf("%c",text2[i]);
- }
- }
- else printf("ne udalos");
- //while(fscanf(g,"%c",&sh) != EOF){printf("%c",sh);}
- fclose(g);
- //while(())
- /*for(int i = 0;i<=255;i++)
- {
- printf("%c - %i\n",(char)i,i);
- }*/
- system("pause>0");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement