东大教务处验证码破解

栏目:行业动态  时间:2017-03-08
手机版

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);

}

}

上一篇:国家级文化生态保护区支撑体系的构建
下一篇:黑龙江公示王法、许文涛、吴柳春、韩立华、魏国臣等18人(简历)

最近更新行业动态