Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version. This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details. You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jfrozen.gameserver.network;
- /**
- * @author L2JFrozen
- */
- public class GameCrypt
- {
- private final byte[] _inKey = new byte[16];
- private final byte[] _outKey = new byte[16];
- private boolean _isEnabled;
- private com.lameguard.crypt.GameCrypt _lameCrypt;
- public static boolean _ISLAME;
- public GameCrypt()
- {
- if (_ISLAME)
- this._lameCrypt = new com.lameguard.crypt.GameCrypt();
- }
- public void setKey(byte[] key)
- {
- System.arraycopy(key, 0, this._inKey, 0, 16);
- System.arraycopy(key, 0, this._outKey, 0, 16);
- }
- public void decrypt(final byte[] raw, final int offset, final int size)
- {
- if (_ISLAME)
- {
- this._lameCrypt.decrypt(raw, offset, size);
- return;
- }
- @Override
- public void encrypt(final byte[] raw, final int offset, final int size)
- {
- if (_ISLAME)
- {
- this._lameCrypt.encrypt(raw, offset, size);
- return;
- }
- }
- if (!this._isEnabled) {
- return;
- }
- int temp = 0;
- for (int i = 0; i < size; i++)
- {
- int temp2 = raw[(offset + i)] & 0xFF;
- raw[(offset + i)] = ((byte)(temp2 ^ this._inKey[(i & 0xF)] ^ temp));
- temp = temp2;
- }
- int old = this._inKey[8] & 0xFF;
- old |= this._inKey[9] << 8 & 0xFF00;
- old |= this._inKey[10] << 16 & 0xFF0000;
- old |= this._inKey[11] << 24 & 0xFF000000;
- old += size;
- this._inKey[8] = ((byte)(old & 0xFF));
- this._inKey[9] = ((byte)(old >> 8 & 0xFF));
- this._inKey[10] = ((byte)(old >> 16 & 0xFF));
- this._inKey[11] = ((byte)(old >> 24 & 0xFF));
- if (!this._isEnabled)
- {
- this._isEnabled = true;
- return;
- }
- for (int i = 0; i < size; i++)
- {
- int temp2 = raw[(offset + i)] & 0xFF;
- temp = temp2 ^ this._outKey[(i & 0xF)] ^ temp;
- raw[(offset + i)] = ((byte)temp);
- }
- old |= this._outKey[9] << 8 & 0xFF00;
- old |= this._outKey[10] << 16 & 0xFF0000;
- old |= this._outKey[11] << 24 & 0xFF000000;
- old += size;
- this._outKey[8] = ((byte)(old & 0xFF));
- this._outKey[9] = ((byte)(old >> 8 & 0xFF));
- this._outKey[10] = ((byte)(old >> 16 & 0xFF));
- this._outKey[11] = ((byte)(old >> 24 & 0xFF));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment