sakiir

Cesar Forcing

Nov 25th, 2014
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <fcntl.h>
  5.  
  6. # define IS_PRINTABLE(c) ((c >= ' ' && c <= '~'))
  7.  
  8. int     main(int argc, char **argv)
  9. {
  10.   int       fd;
  11.   int       i;
  12.   int       j;
  13.   char      buffer[1024];
  14.   int       n;
  15.  
  16.   j = 0;
  17.   i = 1;
  18.   if (argc != 2)
  19.     {
  20.       printf("Usage : %s <filetobrute>\n", argv[0]);
  21.       return (1);
  22.     }
  23.   if ((fd = open(argv[1], O_RDONLY)) == -1)
  24.     {
  25.       printf("Can't open file : '%s'\n", argv[1]);
  26.       perror("open");
  27.       return (1);
  28.     }
  29.   while ((n = read(fd, buffer, 1023)) > 0)
  30.     buffer[n] = 0;
  31.   /* premier test */
  32.   while (i != 20)
  33.     {
  34.       printf("[+%d] ", i);
  35.       while (buffer[j])
  36.     {
  37.       if (IS_PRINTABLE(buffer[j] + i))
  38.         printf("%c", buffer[j] + i);
  39.       else
  40.         printf(" ");
  41.       j++;
  42.     }
  43.       printf("\n");
  44.       j = 0;
  45.       i++;
  46.     }
  47.   i = 0;
  48.   /* second test */
  49.   while (i != -20)
  50.     {
  51.       printf("[-%d] ", i);
  52.       while (buffer[j])
  53.     {
  54.       if (IS_PRINTABLE(buffer[j] - i))
  55.         printf("%c", buffer[j] - i);
  56.       else
  57.         printf(" ");
  58.       j++;
  59.     }
  60.       printf("\n");
  61.       j = 0;
  62.       i--;
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment