E
E
earl_uses2017-02-09 23:59:26
Java
earl_uses, 2017-02-09 23:59:26

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);

The output is 'ѾCOMPLEX' and this is my best result!
How to be?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
longclaps, 2017-02-10
@earl_uses

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'))  # Осложнения

you can try to make a lookup table:
цчфхтурсюяьэъышщжздевгабопмнклийћЦЧФХТУРСЮЯЬЭЪЫШЩЖЗДЕВГАБОПМНКЛИЙЋ
АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯЁабвгдежзийклмнопрстуфхцчшщъыьэюяё

E
earl_uses, 2017-02-10
@earl_uses

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 question

Ask a Question

731 491 924 answers to any question