从一个安卓app看到的
package com.android.ctf;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.android.ctf.crackme1.R;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;
public class MainActivity extends Activity {
private Button btn_register;
private EditText edit_sn;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.edit_sn = (EditText) findViewById(R.id.edit_sn);
this.btn_register = (Button) findViewById(R.id.button_register);
this.btn_register.setOnClickListener(new View.OnClickListener() {
/* class com.android.ctf.MainActivity.AnonymousClass1 */
public void onClick(View v) {
String sn = MainActivity.this.edit_sn.getText().toString();
if (sn.length() != 5 || !"8b1a9953c4611296a827abf8c47804d7".equals(MainActivity.this.encode(sn))) {
Toast.makeText(MainActivity.this, "很遗憾,答错了!", 0).show();
} else {
Toast.makeText(MainActivity.this, "恭喜你,flag{" + sn + "}", 0).show();
}
}
});
}
/* access modifiers changed from: private */
/* access modifiers changed from: public */
private String encode(String string) {
try {
byte[] hash = MessageDigest.getInstance("MD5").digest(string.getBytes("utf-8"));
StringBuilder hex = new StringBuilder(hash.length * 2);
for (byte b : hash) {
if ((b & 255) < 16) {
hex.append("0");
}
hex.append(Integer.toHexString(b & 255));
}
return hex.toString().toLowerCase(Locale.CHINA);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Huh, MD5 should be supported?", e);
} catch (UnsupportedEncodingException e2) {
throw new RuntimeException("Huh, UTF-8 should be supported?", e2);
}
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}