Can anyone tell me what this snippet of code does? In my understanding it returns the sum of the indexes in the string, for example, in string is "Hello" it would return 10? AM I wrong here, please let me know…
public String decrString(final String s) {
final char[] value = new char[s.length()];
for (char index = '\0'; index < s.length(); ++index) {
value[index] = s.charAt(index);
if (index % '\u0002' == 0) {
value[index] -= index;
}
else {
value[index] += index;
}
}
return new String(value);
}
I googled charAt - it simply returns the current index. Java isn't my strongest, first time seeing Java code.
this is kind of Cryptography function and changes a string to an encoded String.(ciphertext).
How it Work?
let's look at some input and output
it starts from first of String and if it place is odd it adds [place index] and if it place is even is mines [place index]
look at first example you can see
AB D F H J Lit generated with this formula(A-0=A)(A+1=B)(A+3=D)(A+5=F)(A+7=H)...look at third example you can find this
9 7 5 3 1it generated such this(9-0=0)(9-2=7)(9-4=5)(9-6=3)(9-8=1)look at forth example it is
56381and generated like this(5-0=5)(5+1=6)(5-2=3)(5+3=8)(5-4=1)