Advertisement
ivandrofly

SyncSafe

Sep 16th, 2016
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. int synchsafe(int in)
  2. {
  3.     int out, mask = 0x7F;
  4.  
  5.     while (mask ^ 0x7FFFFFFF) {
  6.         out = in & ~mask;
  7.         out <<= 1;
  8.         out |= in & mask;
  9.         mask = ((mask + 1) << 8) - 1;
  10.         in = out;
  11.     }
  12.  
  13.     return out;
  14. }
  15.  
  16. int unsynchsafe(int in)
  17. {
  18.     int out = 0, mask = 0x7F000000;
  19.  
  20.     while (mask) {
  21.         out >>= 1;
  22.         out |= in & mask;
  23.         mask >>= 8;
  24.     }
  25.  
  26.     return out;
  27. }
  28.  
  29. // Wikipedia Implementation
  30. // Source: https://en.wikipedia.org/wiki/Synchsafe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement