Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- new P[18]; // P-array
- new S[4][0x100]; // S-boxes
- stock f(x) {
- new h = S[0][x >> 24] + S[1][x >> 16 & 0xff];
- return (h ^ S[2][x >> 8 & 0xff]) + S[3][x & 0xff];
- }
- stock encrypt(&L, &R) {
- for(new i = 0 ; i < 16 ; i += 2) {
- L ^= P[i];
- R ^= f(L);
- R ^= P[i+1];
- L ^= f(R);
- }
- L ^= P[16];
- R ^= P[17];
- swap (L, R);
- }
- stock decrypt(&L, &R) {
- for (new i=16 ; i > 0 ; i -= 2) {
- L ^= P[i+1];
- R ^= f(L);
- R ^= P[i];
- L ^= f(R);
- }
- L ^= P[1];
- R ^= P[0];
- swap (L, R);
- }
- stock key_schedule(const key[], keylen) {
- for(new i = 0 ; i < 18 ; ++i)
- P[i] ^= key[i % keylen];
- new L = 0, R = 0;
- for(new i = 0 ; i < 18 ; i+ = 2) {
- encrypt(L, R);
- P[i] = L; P[i+1] = R;
- }
- for(new i = 0 ; i < 4 ; ++i)
- for(new j = 0 ; j < 0x100 ; j+ = 2) {
- encrypt(L, R);
- S[i][j] = L; S[i][j+1] = R;
- }
- }
- stock swap(a, b) {
- new c = a;
- a = b;
- b = c;
- }
- stock A() {
- new a[100] = "AAAAAAAAAAAAAAaaaaaaaaaa";
- key_schedule(a, sizeof(a));
- printf(a);
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement