Answer the question
In order to leave comments, you need to log in
How can you reverse xor a string in Java if it was originally an AnsiString from Delphi?
There is a string, each character of which has been processed by xor 54 in Delphi 7.
I am reading it from a DB in Java. And I can't decode.
For example:
The word 'Complications' is encrypted in the string
String s = "шЗЭШРЫУЫЮЙ";
String s2 = "";
for (int i = 0; i < s.length(); i++) {
int tmp = s.charAt(i);
s2 += (char)(tmp ^ 54);
}
System.out.println(s2);
Answer the question
In order to leave comments, you need to log in
Here is python3, Java, I'm sorry, I don't know
bb = bytearray("шЗЭШРЫУЫЮЙ".encode('WINDOWS-1251'))
for i in range(len(bb)):
bb[i] ^= 54
print(bb.decode('WINDOWS-1251')) # Осложнения
цчфхтурсюяьэъышщжздевгабопмнклийћЦЧФХТУРСЮЯЬЭЪЫШЩЖЗДЕВГАБОПМНКЛИЙЋ
АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯЁабвгдежзийклмнопрстуфхцчшщъыьэюяё
Made through the encoding lines
public static String xor54Str(String s) {
String sourcePattern = "ёйцукенгшщзхъфывапролджэячсмитьбюЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ";
String resultPattern = "ЋЯАЕЬУЫХОПСГМВНФЦЩЖШЭТРЛЙБЗЪЮДКЧИћяаеьуыхопсгмвнфцщжшэтрлйбзъюдкчи";
StringBuilder res = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
int j = resultPattern.indexOf(s.charAt(i));
if (j == - 1) {
int tmp = s.charAt(i);
res.append((char) (tmp ^ 54));
}
else {
res.append(sourcePattern.charAt(j));
}
}
return res.toString();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question