Encrypting and decoding passwords with character rotation

3

I have a database with a password field, which has a kind of "encryption".

Analyzing the logic: I created users in the system and put the password: 123. When I went to check the password in the bank it was: 032.

If we go for logical reasoning, when I put 1, it generated 0 (a value below); when I put 2, it generated 3 (one value up) and then 3, it generated 2 (one value below).

Other examples:

SENHA                        RESULTADO NO BANCO
abcdefghijklmnopqrstuvwxyz   'cbedgfihkjmlonqpsrutwvyx{
ABCDEFGHIJKLMNOPQRSTUVWXYZ   @CBEDGFIHKJMLONQPSRUTWVYX[
0123456789                   1032547698 

(reading the password it replaces each position with a value above and below).

How can I generate this logic in Java?

    
asked by anonymous 12.04.2015 / 04:49

1 answer

5

As I mentioned in the comments, to rotate the characters to "up" and "down" alternately, this code is enough:

    String s = "ABCDEmasterbbbbbbb123";
    int j = -1;
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        c += j;
        j = -j;
        System.out.print(c);
    }
    System.out.println();

See working at IDEONE .

As you've noticed, switching your example sometimes starts with -1, and sometimes +1. To do this in the code, simply change the line int j = -1; by applying to the logic that determines the "side" of the toggle.

With the question data, in principle the solution is this. What is missing is to find the criterion for determining% initial%, but it is a mere adjustment in the code. For example, it may be that the ID is even or not, or depends on another field in the table. It depends on the analysis of the data.

    
13.04.2015 / 01:36