Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define BUFSIZE 100
  5.  
  6. const char *message =
  7. "          "
  8. "Mr. Watson, come here. I want to see you."
  9. "          ";
  10.  
  11. char buffer[BUFSIZE];
  12.  
  13. typedef unsigned char byte;
  14.  
  15. byte next_LFSR() {
  16.     static byte LFSR = 0xFF;
  17.     byte a = (LFSR & 1 << 3) >> 3;
  18.     byte b = (LFSR & 1 << 4) >> 4;
  19.     byte c = (LFSR & 1 << 5) >> 5;
  20.     byte d = (LFSR & 1 << 7) >> 7;
  21.     byte n = a ^ b ^ c ^ d;
  22.  
  23.     LFSR <<= 1;
  24.     LFSR |= n;
  25.  
  26.     return LFSR;
  27. }
  28.  
  29. void setup() {
  30.     strncpy(buffer, message, strlen(message));
  31. }
  32.  
  33.  
  34. int main() {
  35.     setup();
  36.  
  37.     int len = strlen(message);
  38.     int j = 0;
  39.     for (int i = len; i < len + len; i++) {
  40.         buffer[i] = buffer[j++] ^ next_LFSR();
  41.     }
  42.  
  43.     printf("%s\n", buffer);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement