Advertisement
Shiny_

Blowfish

Sep 1st, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.08 KB | None | 0 0
  1. #include <a_samp>
  2. new P[18];       // P-array
  3. new S[4][0x100]; // S-boxes
  4.  
  5. stock f(x) {
  6.     new h = S[0][x >> 24] + S[1][x >> 16 & 0xff];
  7.     return (h ^ S[2][x >> 8 & 0xff]) + S[3][x & 0xff];
  8. }
  9.  
  10. stock encrypt(&L, &R) {
  11.     for(new i = 0 ; i < 16 ; i += 2) {
  12.         L ^= P[i];
  13.         R ^= f(L);
  14.         R ^= P[i+1];
  15.         L ^= f(R);
  16.     }
  17.     L ^= P[16];
  18.     R ^= P[17];
  19.     swap (L, R);
  20.  }
  21.  
  22. stock decrypt(&L, &R) {
  23.     for (new i=16 ; i > 0 ; i -= 2) {
  24.         L ^= P[i+1];
  25.         R ^= f(L);
  26.         R ^= P[i];
  27.         L ^= f(R);
  28.     }
  29.     L ^= P[1];
  30.     R ^= P[0];
  31.     swap (L, R);
  32. }
  33.  
  34. stock key_schedule(const key[], keylen) {
  35.     for(new i = 0 ; i < 18 ; ++i)
  36.        P[i] ^= key[i % keylen];
  37.    
  38.     new L = 0, R = 0;
  39.    
  40.     for(new i = 0 ; i < 18 ; i+ = 2) {
  41.        encrypt(L, R);
  42.        P[i] = L; P[i+1] = R;
  43.     }
  44.    
  45.     for(new i = 0 ; i < 4 ; ++i)
  46.         for(new j = 0 ; j < 0x100 ; j+ = 2) {
  47.             encrypt(L, R);
  48.             S[i][j] = L; S[i][j+1] = R;
  49.         }
  50.  }
  51.  
  52. stock swap(a, b) {
  53.     new c = a;
  54.     a = b;
  55.     b = c;
  56. }
  57.  
  58. stock A() {
  59.     new a[100] = "AAAAAAAAAAAAAAaaaaaaaaaa";
  60.     key_schedule(a, sizeof(a));
  61.     printf(a);
  62.     return false;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement