// JDK 1.5 ~]~C~A~W~P~D~\ ~O~Y~^~Q. (String.format ~U~H~X ~U~L문~W~P) package cau.util; public class MySqlUtil { public static String toMySQLPassword(String aStr) { int nr = 1345345333; int add = 7; int nr2 = 0x12345671; int size = aStr.length(); for(int i=0;i<size;i++) { if(aStr.charAt(i) == ' ' || aStr.charAt(i) == '\t') continue; /* skipp space in password */ int tmp = (aStr.charAt(i)); nr ^= (((nr & 63)+ add)* tmp) + (nr << 8); nr2 += (nr2 << 8) ^ nr; add += tmp; } int result1=nr & ((1 << 31) -1); /* Don't use sign bit (str2int) */ int result2=nr2 & ((1 << 31) -1); String result = String.format("%08x%08x",new Object[]{new Integer(result1),new Integer(result2)}); return result; } public static void main(String[] args) { System.out.println(MySqlUtil.toMySQLPassword("hahaha")); System.out.println(MySqlUtil.toMySQLPassword("testing")); System.out.println(MySqlUtil.toMySQLPassword("abcd1234")); } }