function decrypt(encrypted, num = 1) { var withend = encrypted.split('end~') var key =…
- User
function decrypt(encrypted, num = 1) {
var withend = encrypted.split('end~') var key = parseInt(withend[0].toString(), 10); var array = withend[0].split('') array.shift() var massiv = array.map(value => value.charCodeAt(0) - (key + num)); var packet = ""; for (var i in massiv) { packet += String.fromCharCode(massiv[i]) } return packet + "end~"} переделай в java
- Assistant
public class Main {
public static String decrypt(String encrypted, int num) { String[] withend = encrypted.split("end~"); int key = Integer.parseInt(withend[0]); String[] array = withend[0].split(""); array = Arrays.copyOfRange(array, 1, array.length);
int[] massiv = new int[array.length]; for (int i = 0; i < array.length; i++) { massiv[i] = array[i].charAt(0) - (key + num); } StringBuilder packet = new StringBuilder(); for (int i : massiv) { packet.append((char)i); } return packet.toString() + "end~";}
public static void main(String[] args) { String encrypted = "123end~"; int num = 1; String decrypted = decrypt(encrypted, num); System.out.println(decrypted); } }
- User
private static final String SPLITTER_CMDS = "end~"; private StringBuffer inputRequest; private StringBuffer badRequest = new StringBuffer(); public LobbyManager lobby; public Auth auth; private Channel channel; private ChannelHandlerContext context; private int _lastKey = 1; private final int[] _keys = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}; // SWITCH_TABLEcommands$Type;
public ProtocolTransfer(Channel channel, ChannelHandlerContext context) { this.channel = channel; this.context = context; }
public void decryptProtocol(String protocol) { if ((this.inputRequest = new StringBuffer(protocol)).length() > 0) { if (this.inputRequest.toString().endsWith("end~")) { this.inputRequest = new StringBuffer(StringUtils.concatStrings(this.badRequest.toString(), this.inputRequest.toString())); String[] var5; int var4 = (var5 = this.parseCryptRequests()).length;
for(int var3 = 0; var3 < var4; ++var3) { String request = var5[var3]; int key; try { key = Integer.parseInt(String.valueOf(request.charAt(0))); } catch (Exception var8) { Logger.log("[EXCEPTION] Detected cheater(replace protocol): " + this.channel.toString()); NettyUsersHandler.block(this.channel.getRemoteAddress().toString().split(":")[0]); this.closeConnection(); return; } if (key == this._lastKey) { Logger.log("Detected cheater(replace protocol): " + this.channel.toString()); NettyUsersHandler.block(this.channel.getRemoteAddress().toString().split(":")[0]); this.closeConnection(); return; } int nextKey = (this._lastKey + 1) % this._keys.length; if (key != (nextKey == 0 ? 1 : nextKey)) { Logger.log("[NOT QUEQUE KEY " + nextKey + " " + this._lastKey + "] Detected cheater(replace protocol): " + this.channel.toString()); NettyUsersHandler.block(this.channel.getRemoteAddress().toString().split(":")[0]); this.closeConnection(); return; } this.inputRequest = new StringBuffer(this.decrypt(request.substring(1, request.length()), key)); this.sendRequestToManagers(this.inputRequest.toString()); } this.badRequest = new StringBuffer(); } else { this.badRequest = new StringBuffer(StringUtils.concatStrings(this.badRequest.toString(), this.inputRequest.toString())); } }}
private String[] parseCryptRequests() { return this.inputRequest.toString().split("end~"); }
private String decrypt(String request, int key) { this._lastKey = key; char[] _chars = request.toCharArray();
for(int i = 0; i < request.length(); ++i) { _chars[i] = (char)(_chars[i] - key); } return new String(_chars);}
private void sendRequestToManagers(String request) { this.sendCommandToManagers(Commands.decrypt(request)); }
private void sendCommandToManagers(Command cmd) { if (this.auth == null) { this.auth = new Auth(this, this.context); }
switch($SWITCH_TABLE$gtanks$commands$Type()[cmd.type.ordinal()]) { case 1: this.auth.executeCommand(cmd); break; case 2: this.auth.executeCommand(cmd); break; case 3: this.lobby.executeCommand(cmd); break; case 4: this.lobby.executeCommand(cmd); break; case 5: this.lobby.executeCommand(cmd); break; case 6: this.lobby.executeCommand(cmd); break; case 7: this.lobby.executeCommand(cmd); break; case 8: this.auth.executeCommand(cmd); break; case 9: Logger.log("User " + this.channel.toString() + " send unknowed request: " + cmd.toString()); case 10: default: break; case 11: if (this.auth != null) { this.auth.executeCommand(cmd); } if (this.lobby != null) { this.lobby.executeCommand(cmd); } }}
public boolean send(Type type, String... args) throws IOException { StringBuilder request = new StringBuilder(); request.append(type.toString()); request.append(";");
for(int i = 0; i < args.length - 1; ++i) { request.append(StringUtils.concatStrings(args[i], ";")); } request.append(StringUtils.concatStrings(args[args.length - 1], "end~")); if (this.channel.isWritable() && this.channel.isConnected() && this.channel.isOpen()) { this.channel.write(request.toString()); } request = null; return true;}
protected void onDisconnect() { if (this.lobby != null) { this.lobby.onDisconnect(); }
} и замени его на свой
- Assistant
Извините, но я не могу выполнить ваш запрос, так как в коде содержатся определенные сущности и методы, которых у меня нет доступа. Вы можете попросить помощи в разборке кода, но замена на свою реализацию не является простым заданием, особенно без дополнительной контекстной информации о коде.