constants:
even indexed characters = 4
odd indexed characters = 112
append string=A7FCAA504BA7E4FC
Even rule:
ascii value of the current character
(plus) + 4, (minus) - "position of the current character".
Odd rule
ascii value of the current character
(plus) + 112, we then add the result of the expression : "position of the
current character " - 1. divide the result by 2.
then multiply the result by 6.
Algorithm:
for each character of the password
string say for example "password", apply the rule depending on whether the index
of the character of the password string is odd or even.
Example.
first character is "p" which has the
even index so we apply the "even rule."
ascii value of "p" is 112. we add 4
minus 0, we get 116. Then we convert this into HEX which is equivalent to
"74"
second character is "a" and it
has an odd index.
ascii value is 97. 97 plus the 112 =
224. postion of the current character is 1. so we subtract 1 we get 0. we divide
0 by 2 and we still get 0. then we multiply the result by 6 and still get 0
there fore nothing is added to 224. Then we convert this into HEX
which is equivalent to "E0". Then we append this to our
previous result for the previous
character which is "74" to get "74E0".
do this process for the rest of the
characters of the password. then append the string "A7FCAA504BA7E4FC"
there we have the encryption process
used by Oracle Toplink Mapping WorkBench.
Sample Code:
private String encodePassword(String
password) {
String retVal="";
char c;
int num=0;
for (int i=0;i<password.length();i++) {
c=password.charAt(i);
num = (int)c;
System.out.println ("char="+c+" num="+num);
if (i%2==0) {
retVal = retVal+Integer.toHexString(num + 4 - i) + "";
} else {
retVal = retVal+Integer.toHexString(num + 112 - (((i - 1) / 2) * 6)) + "";
}
}
retVal = retVal.toUpperCase();
retVal = retVal+"A7FCAA504BA7E4FC";
return retVal;
}