// 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")); } }