OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

[/] [fpga-cf/] [trunk/] [java/] [src/] [edu/] [byu/] [cc/] [plieber/] [fpgaenet/] [modmod/] [MD5Widget.java] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 peteralieb
package edu.byu.cc.plieber.fpgaenet.modmod;
2
import java.util.ArrayList;
3
 
4
import com.trolltech.qt.gui.*;
5
import com.trolltech.qt.gui.QSizePolicy.Policy;
6
 
7
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
8
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
9
import edu.byu.cc.plieber.util.StringUtil;
10
 
11
public class MD5Widget extends ModuleControlWidget{
12
 
13
    private QVBoxLayout mainLayout;
14
    private QHBoxLayout formatLayout;
15
 
16
    private QLabel lblTitle;
17
 
18
    private QRadioButton radASCII;
19
    private QRadioButton radHex;
20
 
21
    private QLineEdit txtRead;
22
    private QPushButton btnCalculate;
23
    private QLineEdit txtResult;
24
 
25
    public MD5Widget(QWidget parent, FCPProtocol protocol){
26
        super(parent);
27
        fcpProtocol = protocol;
28
        createWidgets();
29
        connectSignalsAndSlots();
30
    }
31
 
32
    FCPProtocol fcpProtocol;
33
 
34
        private void createWidgets() {
35
                mainLayout = new QVBoxLayout(this);
36
                this.setLayout(mainLayout);
37
                lblTitle = new QLabel("MD5 Calculator");
38
                mainLayout.addWidget(lblTitle);
39
                formatLayout = new QHBoxLayout();
40
                mainLayout.addLayout(formatLayout);
41
                radASCII = new QRadioButton("ASCII");
42
                radASCII.setChecked(true);
43
                radHex = new QRadioButton("Hex");
44
                formatLayout.addWidget(radASCII);
45
                formatLayout.addWidget(radHex);
46
                formatLayout.addStretch();
47
                txtRead = new QLineEdit();
48
                btnCalculate = new QPushButton("Calculate");
49
                btnCalculate.setSizePolicy(new QSizePolicy(Policy.Maximum, Policy.Maximum));
50
                txtResult = new QLineEdit();
51
                mainLayout.addWidget(txtRead);
52
                mainLayout.addWidget(btnCalculate);
53
                mainLayout.addWidget(txtResult);
54
                mainLayout.addStretch();
55
 
56
        }
57
 
58
        private void connectSignalsAndSlots() {
59
                btnCalculate.clicked.connect(this, "calculate()");
60
        }
61
 
62
        @Override
63
        public void setChannelNumber(int channelNumber) {
64
                this.channelNumber = channelNumber;
65
                lblTitle.setText("MD5 Calculator (Channel " + channelNumber + ")");
66
        }
67
 
68
        @SuppressWarnings("unused")
69
        private void calculate() {
70
                String text = txtRead.text();
71
                ArrayList<Byte> pass;
72
                long len = 0;
73
                if (radASCII.isChecked()) {
74
                        pass = StringUtil.stringToByteList(text);
75
                        len = text.length();
76
                }
77
                else {
78
                        String[] tokens = text.split(" ");
79
                        pass = new ArrayList<Byte>();
80
                        for (String bytestr : tokens) {
81
                                pass.add((byte) Integer.parseInt(bytestr, 16));
82
                        }
83
                        len = pass.size();
84
                }
85
                pass.add(new Byte((byte)0x80));
86
                while (pass.size()*8 % 512 != 448) {
87
                        pass.add(new Byte((byte)0x00));
88
                }
89
                len = len * 8;
90
                pass.add(new Byte((byte)((len) & 0xff)));
91
                pass.add(new Byte((byte)((len >> 8) & 0xff)));
92
                pass.add(new Byte((byte)((len >> 16) & 0xff)));
93
                pass.add(new Byte((byte)((len >> 24) & 0xff)));
94
                pass.add(new Byte((byte)((len >> 32) & 0xff)));
95
                pass.add(new Byte((byte)((len >> 40) & 0xff)));
96
                pass.add(new Byte((byte)((len >> 48) & 0xff)));
97
                pass.add(new Byte((byte)((len >> 56) & 0xff)));
98
                try {
99
                        fcpProtocol.send(channelNumber, pass, pass.size());
100
                        fcpProtocol.sendDataRequest(channelNumber, 16);
101
                } catch (FCPException e) {
102
                        // TODO Auto-generated catch block
103
                        e.printStackTrace();
104
                }
105
                byte[] bytes = fcpProtocol.getDataResponse();
106
                txtResult.clear();
107
                txtResult.setText(StringUtil.arrayToHexString(bytes));
108
        }
109
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.