import java.io.*; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class MD5Encrypt { public static String byteArrayToString(byte[] b) { StringBuffer resultSb=new StringBuffer(); for(int i=0;i<b.length;i++) { resultSb.append(byteToNumString(b[i])); } return resultSb.toString(); } private static String byteToNumString(byte b) { int a=b; if(a<0) a=256+a; return String.valueOf(a); } public static String MD5Encode(String originString) { String resultString=null; try { resultString=new String(originString); MessageDigest md=MessageDigest.getInstance("MD5"); resultString=byteArrayToString(md.digest(resultString.getBytes())); }catch(Exception e) { e.printStackTrace(); } return resultString; } public static void main(String[] args)throws Exception //一定要抛出异常 { MD5Encrypt md5encrypt=new MD5Encrypt(); boolean i=true; int sum=0; while(i) { InputStreamReader r=new InputStreamReader(System.in); BufferedReader c=new BufferedReader(r); String input=c.readLine(); String outcome=md5encrypt.MD5Encode(input); int l=outcome.length(); byte[] b=outcome.getBytes(); for(int j=0;j<l;j++) { sum+=b[j]; } System.out.println(md5encrypt.MD5Encode(input)); String sum1=String.valueOf(sum); String sum2=sum1.substring(0,3); int sum3=Integer.parseInt(sum2); System.out.println(sum3); } } }