Untitled
unknown
java
2 years ago
622 B
10
Indexable
public String decode(String message, int offset) {
offset = offset % 26;
final byte spaceCode = (byte) 32;
byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] == spaceCode) {
continue;
}
if (bytes[i] - (byte) offset < 65) {
bytes[i] = (byte) (91 - (offset - (bytes[i] - 65)));
}
else {
bytes[i] = (byte) (bytes[i] - (byte) offset);
}
}
return new String(bytes, StandardCharsets.UTF_8);
}Editor is loading...