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/] [SHA1Widget.java] - Blame information for rev 2

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 SHA1Widget extends ModuleControlWidget{
12
 
13
    public SHA1Widget(QWidget parent, FCPProtocol protocol){
14
        super(parent);
15
        fcpProtocol = protocol;
16
        createWidgets();
17
        connectSignalsAndSlots();
18
    }
19
 
20
    private QVBoxLayout mainLayout;
21
    private QHBoxLayout formatLayout;
22
 
23
    private QLabel lblTitle;
24
 
25
    private QRadioButton radASCII;
26
    private QRadioButton radHex;
27
 
28
    private QLineEdit txtRead;
29
    private QPushButton btnCalculate;
30
    private QLineEdit txtResult;
31
 
32
    FCPProtocol fcpProtocol;
33
 
34
        private void createWidgets() {
35
                mainLayout = new QVBoxLayout(this);
36
                this.setLayout(mainLayout);
37
                lblTitle = new QLabel("SHA1 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
        private void connectSignalsAndSlots() {
58
                btnCalculate.clicked.connect(this, "calculate()");
59
        }
60
 
61
        @Override
62
        public void setChannelNumber(int channelNumber) {
63
                this.channelNumber = channelNumber;
64
                lblTitle.setText("SHA1 Calculator (Channel " + channelNumber + ")");
65
        }
66
 
67
        @SuppressWarnings("unused")
68
        private void calculate() {
69
                String text = txtRead.text();
70
                ArrayList<Byte> pass;
71
                long len = 0;
72
                if (radASCII.isChecked()) {
73
                        pass = StringUtil.stringToByteList(text);
74
                        len = text.length();
75
                }
76
                else {
77
                        String[] tokens = text.split(" ");
78
                        pass = new ArrayList<Byte>();
79
                        for (String bytestr : tokens) {
80
                                pass.add((byte) Integer.parseInt(bytestr, 16));
81
                        }
82
                        len = pass.size();
83
                }
84
                pass.add(new Byte((byte)0x80));
85
                while (pass.size()*8 % 512 != 448) {
86
                        pass.add(new Byte((byte)0x00));
87
                }
88
                len = len * 8;
89
                pass.add(new Byte((byte)((len >> 56) & 0xff)));
90
                pass.add(new Byte((byte)((len >> 48) & 0xff)));
91
                pass.add(new Byte((byte)((len >> 40) & 0xff)));
92
                pass.add(new Byte((byte)((len >> 32) & 0xff)));
93
                pass.add(new Byte((byte)((len >> 24) & 0xff)));
94
                pass.add(new Byte((byte)((len >> 16) & 0xff)));
95
                pass.add(new Byte((byte)((len >> 8) & 0xff)));
96
                pass.add(new Byte((byte)((len) & 0xff)));
97
                try {
98
                        fcpProtocol.send(channelNumber, pass, pass.size());
99
                        fcpProtocol.sendDataRequest(channelNumber, 20);
100
                } catch (FCPException e) {
101
                        // TODO Auto-generated catch block
102
                        e.printStackTrace();
103
                }
104
                byte[] bytes = fcpProtocol.getDataResponse();
105
                txtResult.clear();
106
                txtResult.setText(StringUtil.arrayToHexString(bytes));
107
        }
108
}

powered by: WebSVN 2.1.0

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