东大教务处验证码破解
class Point {
int x, y;
Point(int x, int y) {
this.x= x;
this.y= y;
}
@Override
public int hashCode() {
return x ^ y;
}
@Override
public boolean equals(Object obj) {
Point p = (Point) obj;
return p.x==x && p.y== y;
}
boolean less(Point p) {
if (x== p.x)
return y < p.y;
else
return x < p.x;
}
}
class Country {
ArrayList
a=new ArrayList
();
Country() {
}
Country(ArrayList
a) {
this.a=new ArrayList
();
for (Point p : a) {
this.a.add(new Point(p.x, p.y));
}
}
}
class Go {
int[][] a;
int[][] ans;
int[][] id;
ArrayList countries=new ArrayList();
int w, h;
int[] color;
static int COLOR_DIS=55;
static int NOISE_LOWER_BOUND=5, NOISE_UPPER_BOUND=4;
public Go(int[][] a) {
this.a= a;
w = a.length;
h =a[0].length;
id =new int[w][h];
expand();
// delNoise();
initColor(countries.size());
getAns();
}
void cout(String s) {
System.out.println(s);
}
void getAns() {
ans =new int[w][h];
for (int i=0; i < countries.size(); i++) {
Country c = countries.get(i);
for (int j=0; j =0; i--) {
Country c = countries.get(i);
if (c.a.size() NOISE_UPPER_BOUND) {
zero.a.addAll(c.a);
countries.remove(i);
}
}
}
boolean hasRadius(Country c, int r) {
for (int i=0; i < c.a.size(); i++) {
int m=c.a.get(i).x, n= c.a.get(i).y;
boolean ok=true;
out: for (int j=-r; j <=r; j++) {
for (int k=-(r - Math.abs(j)); k <=r - Math.abs(j); k++) {
int x=m + j, y=n + k;
if (legal(x, y) && id[x][y] != id[m][n]) {
ok =false;
break out;
}
}
}
if (ok)
return true;
}
return false;
}
int radius(Country c) {
int r=(int) Math.sqrt(c.a.size()), l=0;
while (l > 1;
if (hasRadius(c, m))
l =m + 1;
else
r = m;
}
return r;
}
void expand() {
countries.add(new Country());
for (int i=0; i < w; i++) {
for (int j=0; j < h; j++) {
if (id[i][j]==0) {
countries.add(new Country());
go(countries.get(countries.size() - 1), i, j, countries.size() - 1);
}
}
}
}
void go(Country country, int fx, int fy, int cnt) {
int dir[]={ 0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, -1, -1, 1 };
id[fx][fy] = cnt;
country.a.add(new Point(fx, fy));
for (int i=0; i < dir.length; i +=2) {
int x=fx + dir[i], y=fy + dir[i + 1];
if (legal(x, y) && id[x][y]==0 && dis(a[fx][fy], a[x][y]) < COLOR_DIS) {
go(country, x, y, cnt);
}
}
}
void initColor(int cnt) {
color =new int[cnt];
double per=255.0 / Math.pow(cnt, 1.0 / 3);
int ci=0;
for (int i=0; i < 255; i += per) {
for (int j=0; j < 255; j += per) {
for (int k=0; k < 255; k += per) {
color[ci++]=i | j << 8 | k <=0 && y >=0 && x < w && y < h;
}
int dis(int x, int y) {
int ans=0;
for (int i=0; i >=8;
y >>=8;
}
ans =(int) Math.sqrt(ans);
return ans;
}
}
class Data {
Country[] xing =new Country[128];
Point[][] wei =new Point[128][4];
void save() {
PrintWriter cout =null;
try {
cout =new PrintWriter(new File("haha.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
for (char c='0'; c <='9'; c++) {
print(cout, c);
}
for (char c='a'; c <='z'; c++) {
print(cout, c);
}
for (char c='A'; c <='Z'; c++) {
print(cout, c);
}
cout.close();
}
void print(PrintWriter cout, char c) {
cout.println();
cout.print(c);
for (int i=0; i < 4; i++)
if (wei[c][i]==null)
continue;
else
cout.print(" " + wei[c][i].x + " " + wei[c][i].y);
if (xing[c]==null)
return;
for (Point p : xing[c].a)
cout.print(" " + p.x + " " + p.y);
}
String gets(char c) {
String s ="" + c;
for (int i=0; i < 4; i++) {
if (wei[c][i]==null) {
s +=" (_,_)";
} else {
s +=" (" + wei[c][i].x + "," + wei[c][i].y + ")";
}
}
if (xing[c] !=null) {
s +="======";
for (Point p : xing[c].a) {
s +="(" + p.x + "," + p.y + ")";
}
}
return s + "\n";
}
public String toString() {
String s ="";
for (char c='0'; c <='9'; c++) {
s += gets(c);
}
for (char c='a'; c <='z'; c++) {
s += gets(c);
}
for (char c='A'; c <='Z'; c++) {
s += gets(c);
}
return s;
}
void sort(ArrayList
a) {
for (int i=0; i < a.size(); i++) {
for (int j=0; j < a.size(); j++) {
if (a.get(i).less(a.get(j))) {
Point temp = a.get(i);
a.set(i, a.get(j));
a.set(j, temp);
}
}
}
}
void uniq(ArrayList
a) {
for (int i=a.size() - 1; i > 0; i--)
if (a.get(i).equals(a.get(i - 1))) {
a.remove(i);
}
}
void update(ArrayList
a) {
int x=a.get(0).x, y=a.get(0).y;
for (Point p : a) {
p.x -= x;
p.y -= y;
}
}
void set(String s, Country country) {
if (country==null || country.a==null)
return;
Scanner cin =new Scanner(s);
String c = cin.next();
if (country.a.size()==0) {
System.out.println("Country.a.size() cannot be zero !!!");
}
if (country.a.size()==1) {
int pos=cin.nextInt() - 1;
wei[c.charAt(0)][pos]=country.a.get(0);
} else {
sort(country.a);
uniq(country.a);
update(country.a);
xing[c.charAt(0)]= country;
}
cin.close();
}
}
public class Main extends JFrame {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
new Main();
}
File[] files =new File("img").listFiles();
int fileIndex=0;
JPanel protoPanel =new JPanel(), nowPanel=new JPanel();
JTextField txt =new JTextField();
JTextArea area =new JTextArea(6, 0);
Container content;
int proto[][], now[][];
BufferedImage protoImage, nowImage;
ArrayList
selectedPoints;
Data data =new Data();
Go go;
void initControl() {
Font f =new Font("Ubuntu Mono", Font.BOLD, 30);
txt.setFont(f);
area.setFont(f);
area.setEditable(false);
txt.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode()== KeyEvent.VK_ENTER) {
data.set(txt.getText(), new Country(selectedPoints));
area.setText(data.toString());
txt.setText("");
selectedPoints =null;
protoPanelPaint();
}
}
});
}
Main() {
loadProto();
loadNow();
setTitle("agnomen decoder");
content = getContentPane();
content.setLayout(new BorderLayout());
JPanel pane =new JPanel(new GridLayout());
pane.add(protoPanel);
pane.add(nowPanel);
content.add(pane, BorderLayout.CENTER);
JPanel editPane =new JPanel(new BorderLayout());
initControl();
editPane.add(txt, BorderLayout.NORTH);
editPane.add(new JScrollPane(area), BorderLayout.CENTER);
content.add(editPane, BorderLayout.NORTH);
setExtendedState(MAXIMIZED_BOTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
protoPanel.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
protoPanel.grabFocus();
}
@Override
public void mouseClicked(MouseEvent e) {
double w=(double) protoPanel.getWidth() / proto.length,
h =(double) protoPanel.getHeight() / proto[0].length;
int x=(int) (e.getX() / w), y=(int) (e.getY() / h);
int color= proto[x][y];
int b=color & 255, g=(color >> 8) & 255, r=(color >> 16) & 255;
setTitle(x + " " + y + " " + r + " " + g + " " + b);
if (e.getButton()== MouseEvent.BUTTON3) {
selectedPoints = go.countries.get(go.id[x][y]).a;
protoPanelPaint();
} else if (e.getButton()== MouseEvent.BUTTON1) {
if (e.isControlDown()) {
if (selectedPoints==null)
return;
for (Point p : selectedPoints) {
if (p.x==x && p.y== y) {
selectedPoints.remove(p);
protoPanelPaint();
return;
}
}
} else {
if (selectedPoints==null)
selectedPoints =new ArrayList
();
selectedPoints.add(new Point(x, y));
protoPanelPaint();
}
}
}
});
nowPanel.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
int x= e.getWheelRotation();
Go.COLOR_DIS += x;
setTitle(Go.COLOR_DIS + "");
loadNow();
nowPanelPaint();
}
});
protoPanel.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode()== KeyEvent.VK_DOWN) {
fileIndex =(fileIndex + 1) % files.length;
selectedPoints =null;
loadProto();
loadNow();
repaint();
} else if (e.getKeyCode()== KeyEvent.VK_UP) {
fileIndex =(fileIndex - 1 + files.length) % files.length;
selectedPoints =null;
loadProto();
loadNow();
repaint();
} else if (e.getKeyCode()==KeyEvent.VK_S && e.isControlDown()) {
data.save();
} else if (e.getKeyCode()== KeyEvent.VK_SPACE) {
selectedPoints =null;
protoPanelPaint();
}
}
});
}
@Override
public void paint(Graphics g) {
protoPanelPaint();
nowPanelPaint();
}
void loadNow() {
go =new Go(proto);
now = go.ans;
nowImage = toImg(now);
}
void loadProto() {
try {
protoImage = ImageIO.read(files[fileIndex]);
proto = toArray(protoImage);
} catch (IOException e) {
e.printStackTrace();
}
}
int[][] copy(int[][] src) {
int[][] a=new int[src.length][src[0].length];
for (int i=0; i < src.length; i++) {
for (int j=0; j < src[i].length; j++) {
a[i][j] = src[i][j];
}
}
return a;
}
void nowPanelPaint() {
nowPanel.getGraphics().drawImage(nowImage, 0, 0, nowPanel.getWidth(), nowPanel.getHeight(), null);
}
void protoPanelPaint() {
int[][] midArray= copy(proto);
addColor(midArray);
BufferedImage midImg = toImg(midArray);
protoPanel.getGraphics().drawImage(midImg, 0, 0, protoPanel.getWidth(), protoPanel.getHeight(), null);
}
void addColor(int[][] a) {
if (selectedPoints==null)
return;
for (Point p : selectedPoints) {
a[p.x][p.y] =0xff0000;
}
}
BufferedImage toImg(int[][] a) {
BufferedImage pic =new BufferedImage(a.length, a[0].length, BufferedImage.TYPE_INT_RGB);
for (int i=0; i < pic.getWidth(); i++) {
for (int j=0; j < pic.getHeight(); j++) {
pic.setRGB(i, j, a[i][j]);
}
}
return pic;
}
int[][] toArray(BufferedImage img) {
int a[][]=new int[img.getWidth()][img.getHeight()];
for (int i=0; i < img.getWidth(); i++) {
for (int j=0; j < img.getHeight(); j++) {
a[i][j] = img.getRGB(i, j);
}
}
return a;
}
void cout(String s) {
System.out.print(s);
}
}
最近更新行业动态
- 全国211大学排名榜单公布,划分2个行政级别!
- 小学语文阅读专项十五——说明文阅读的简单方法
- 线上学校为“数字化教师”赋能
- 广钢3所“大公办”幼儿园集中开园
- 安徽师范大学附属巢湖实验中学今秋正式招新生
- 反驳俞敏洪,中小学教师绝对有资格,也绝对能胜任教学岗位
- 高考275人上清华北大,衡水中学却被质疑,看到这张图大家沉默了
- 大学生入党和不入党有什么差别?看完这篇文章你就知道了
- 三年级数学期末考试,学生考了60分,全班第3名,妈妈听后却哭了
- “鬼才”历史老师:重大“标志性”事件绘成表,初中3年不再愁
- 如果学霸当中小学老师,会不会提升档次?网友:学霸不适合当老师
- 中学校服收2300元:家委会别没“存在感”
- 三年级语文修改病句练习题汇总,很全面(可打印),期中考试要考
- 江苏最憋屈的大学,曾是全国重点大学,如今却连211都没混上!
- 高中数学:函数和导数题型你会做吗?
- 2020部编版三年级语文下册,第二单元测试卷,附答案
- 幼儿园开学时间终于敲定了,家长态度不一,对此,你怎么看待?
- 重要提醒:国务院将体育纳入高中学业水平测试是否影响你?
- 重磅!四川公办民办高中取消自主招生考试,录取以中考成绩为依据!
- 西湖大学28位创始捐赠人中9位河南老乡 施一公:我很感谢他们
- 初中数学教学的几点思考
- 揭秘全美顶尖公立高中新泽西High Tech High
- 幼儿园小女生每天闯关1小时,妈妈解脱了,她却驶上“快车道”!
- 初中生“早恋”时,多半会偷偷做“3件事”,尤其第1件太真实!
- 网传贵阳一幼儿园20名幼儿食物中毒 教育部门辟谣