Simple algorithm for mixing/obfuscating a string with pre-defined chars

后端 未结 5 631
北恋
北恋 2021-01-31 05:39

I have a string as follows:

  • Its length is 10.
  • It represents base 36 and as such includes digits and uppercase letters.
  • The origin of the st
5条回答
  •  走了就别回头了
    2021-01-31 06:11

    Just reverse the bits on your counter before doing the base36 encoding. Something like this

    public static void main(String[] args) {
        for (int i = 1400; i < 1420; i++) {
            String base36 = Integer.toString(i, 36);
            String reverse = Integer.toString(Integer.reverse(i << 1), 36);
    
            System.out.println("i: " + i + "  base36: " + base36 + 
                                           "  reverse: " + reverse);
        }
    }
    

    Result:

    i: 1400  base36: 12w  reverse: 48ya68
    i: 1401  base36: 12x  reverse: m08ao0
    i: 1402  base36: 12y  reverse: d4laf4
    i: 1403  base36: 12z  reverse: uvvaww
    i: 1404  base36: 130  reverse: 8orsao
    i: 1405  base36: 131  reverse: qg1ssg
    i: 1406  base36: 132  reverse: hkesjk
    i: 1407  base36: 133  reverse: zbot1c
    i: 1408  base36: 134  reverse: 8464g
    i: 1409  base36: 135  reverse: hze6m8
    i: 1410  base36: 136  reverse: 93r6dc
    i: 1411  base36: 137  reverse: qv16v4
    i: 1412  base36: 138  reverse: 4nxo8w
    i: 1413  base36: 139  reverse: mf7oqo
    i: 1414  base36: 13a  reverse: djkohs
    i: 1415  base36: 13b  reverse: vauozk
    i: 1416  base36: 13c  reverse: 2g0x6o
    i: 1417  base36: 13d  reverse: k7axog
    i: 1418  base36: 13e  reverse: bbnxfk
    i: 1419  base36: 13f  reverse: t2xxxc
    

提交回复
热议问题