Breeze

LFSR 128-bit algorithm (C++)

Mar 16th, 2012
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <bitset>
  4. using namespace std;
  5.  
  6. int LFSR (void)
  7. {
  8.   static unsigned long SHH = 0xFFFFFFFF;
  9.   static unsigned long SHL = 0xFFFFFFFF;
  10.   static unsigned long SLH = 0xFFFFFFFF;
  11.   static unsigned long SLL = 0xFFFFFFFF;
  12.  
  13.   char counter = 32;
  14.   unsigned int value = 0;
  15.   do {
  16.     int S = (( (SLL>>2)^(SLL>>27)^(SLL>>29)^SLL ) & 1);
  17.     SLL = (SLL>>1) | ((SLH & 1)<<31);
  18.     SLH = (SLH>>1) | ((SHL & 1)<<31);
  19.     SHL = (SHL>>1) | ((SHH & 1)<<31);
  20.     SHH = (SHH>>1) | (S<<31);
  21.     counter--;
  22.     value = (value<<1) | (SLL & 1);
  23.   } while (counter > 0);
  24.   return value;
  25. }
  26.  
  27. int _tmain(int argc, _TCHAR* argv[])
  28. {
  29.   for (int i=0; i<0xFFFF; i++) {
  30.     std::cout << std::bitset<32>(LFSR());
  31.   }
  32.   std::getchar();
  33.   return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment