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] - Diff between revs 2 and 7

Only display areas with differences | Details | Blame | View Log

Rev 2 Rev 7
package edu.byu.cc.plieber.fpgaenet.modmod;
package edu.byu.cc.plieber.fpgaenet.modmod;
 
import java.io.IOException;
 
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.ArrayList;
 
 
import com.trolltech.qt.gui.*;
import com.trolltech.qt.gui.*;
import com.trolltech.qt.gui.QSizePolicy.Policy;
import com.trolltech.qt.gui.QSizePolicy.Policy;
 
 
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
import edu.byu.cc.plieber.fpgaenet.fcp.FCPException;
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
import edu.byu.cc.plieber.fpgaenet.fcp.FCPProtocol;
import edu.byu.cc.plieber.util.StringUtil;
import edu.byu.cc.plieber.util.StringUtil;
 
 
public class SHA1Widget extends ModuleControlWidget{
public class SHA1Widget extends ModuleControlWidget{
 
 
 
        public static void main(String[] args) {
 
                QApplication.initialize(args);
 
 
 
                FCPProtocol p = null;
 
                try {
 
                        p = new FCPProtocol();
 
                        p.connect(InetAddress.getByName("10.0.1.42"));
 
                        while (!p.isConnected());
 
                } catch (IOException e) {
 
                        // TODO Auto-generated catch block
 
                        e.printStackTrace();
 
                }
 
                SHA1Widget w = new SHA1Widget(null, p);
 
                w.setChannelNumber(6);
 
                w.show();
 
                QApplication.exec();
 
                p.disconnect();
 
 
 
        }
 
 
    public SHA1Widget(QWidget parent, FCPProtocol protocol){
    public SHA1Widget(QWidget parent, FCPProtocol protocol){
        super(parent);
        super(parent);
        fcpProtocol = protocol;
        fcpProtocol = protocol;
        createWidgets();
        createWidgets();
        connectSignalsAndSlots();
        connectSignalsAndSlots();
    }
    }
 
 
    private QVBoxLayout mainLayout;
    private QVBoxLayout mainLayout;
    private QHBoxLayout formatLayout;
    private QHBoxLayout formatLayout;
 
 
    private QLabel lblTitle;
    private QLabel lblTitle;
 
 
    private QRadioButton radASCII;
    private QRadioButton radASCII;
    private QRadioButton radHex;
    private QRadioButton radHex;
 
 
    private QLineEdit txtRead;
    private QLineEdit txtRead;
    private QPushButton btnCalculate;
    private QPushButton btnCalculate;
    private QLineEdit txtResult;
    private QLineEdit txtResult;
 
 
    FCPProtocol fcpProtocol;
    FCPProtocol fcpProtocol;
 
 
        private void createWidgets() {
        private void createWidgets() {
                mainLayout = new QVBoxLayout(this);
                mainLayout = new QVBoxLayout(this);
                this.setLayout(mainLayout);
                this.setLayout(mainLayout);
                lblTitle = new QLabel("SHA1 Calculator");
                lblTitle = new QLabel("SHA1 Calculator");
                mainLayout.addWidget(lblTitle);
                mainLayout.addWidget(lblTitle);
                formatLayout = new QHBoxLayout();
                formatLayout = new QHBoxLayout();
                mainLayout.addLayout(formatLayout);
                mainLayout.addLayout(formatLayout);
                radASCII = new QRadioButton("ASCII");
                radASCII = new QRadioButton("ASCII");
                radASCII.setChecked(true);
                radASCII.setChecked(true);
                radHex = new QRadioButton("Hex");
                radHex = new QRadioButton("Hex");
                formatLayout.addWidget(radASCII);
                formatLayout.addWidget(radASCII);
                formatLayout.addWidget(radHex);
                formatLayout.addWidget(radHex);
                formatLayout.addStretch();
                formatLayout.addStretch();
                txtRead = new QLineEdit();
                txtRead = new QLineEdit();
                btnCalculate = new QPushButton("Calculate");
                btnCalculate = new QPushButton("Calculate");
                btnCalculate.setSizePolicy(new QSizePolicy(Policy.Maximum, Policy.Maximum));
                btnCalculate.setSizePolicy(new QSizePolicy(Policy.Maximum, Policy.Maximum));
                txtResult = new QLineEdit();
                txtResult = new QLineEdit();
                mainLayout.addWidget(txtRead);
                mainLayout.addWidget(txtRead);
                mainLayout.addWidget(btnCalculate);
                mainLayout.addWidget(btnCalculate);
                mainLayout.addWidget(txtResult);
                mainLayout.addWidget(txtResult);
                mainLayout.addStretch();
                mainLayout.addStretch();
        }
        }
 
 
        private void connectSignalsAndSlots() {
        private void connectSignalsAndSlots() {
                btnCalculate.clicked.connect(this, "calculate()");
                btnCalculate.clicked.connect(this, "calculate()");
        }
        }
 
 
        @Override
        @Override
        public void setChannelNumber(int channelNumber) {
        public void setChannelNumber(int channelNumber) {
                this.channelNumber = channelNumber;
                this.channelNumber = channelNumber;
                lblTitle.setText("SHA1 Calculator (Channel " + channelNumber + ")");
                lblTitle.setText("SHA1 Calculator (Channel " + channelNumber + ")");
        }
        }
 
 
        @SuppressWarnings("unused")
        @SuppressWarnings("unused")
        private void calculate() {
        private void calculate() {
                String text = txtRead.text();
                String text = txtRead.text();
                ArrayList<Byte> pass;
                ArrayList<Byte> pass;
                long len = 0;
                long len = 0;
                if (radASCII.isChecked()) {
                if (radASCII.isChecked()) {
                        pass = StringUtil.stringToByteList(text);
                        pass = StringUtil.stringToByteList(text);
                        len = text.length();
                        len = text.length();
                }
                }
                else {
                else {
                        String[] tokens = text.split(" ");
                        String[] tokens = text.split(" ");
                        pass = new ArrayList<Byte>();
                        pass = new ArrayList<Byte>();
                        for (String bytestr : tokens) {
                        for (String bytestr : tokens) {
                                pass.add((byte) Integer.parseInt(bytestr, 16));
                                pass.add((byte) Integer.parseInt(bytestr, 16));
                        }
                        }
                        len = pass.size();
                        len = pass.size();
                }
                }
                pass.add(new Byte((byte)0x80));
                pass.add(new Byte((byte)0x80));
                while (pass.size()*8 % 512 != 448) {
                while (pass.size()*8 % 512 != 448) {
                        pass.add(new Byte((byte)0x00));
                        pass.add(new Byte((byte)0x00));
                }
                }
                len = len * 8;
                len = len * 8;
                pass.add(new Byte((byte)((len >> 56) & 0xff)));
                pass.add(new Byte((byte)((len >> 56) & 0xff)));
                pass.add(new Byte((byte)((len >> 48) & 0xff)));
                pass.add(new Byte((byte)((len >> 48) & 0xff)));
                pass.add(new Byte((byte)((len >> 40) & 0xff)));
                pass.add(new Byte((byte)((len >> 40) & 0xff)));
                pass.add(new Byte((byte)((len >> 32) & 0xff)));
                pass.add(new Byte((byte)((len >> 32) & 0xff)));
                pass.add(new Byte((byte)((len >> 24) & 0xff)));
                pass.add(new Byte((byte)((len >> 24) & 0xff)));
                pass.add(new Byte((byte)((len >> 16) & 0xff)));
                pass.add(new Byte((byte)((len >> 16) & 0xff)));
                pass.add(new Byte((byte)((len >> 8) & 0xff)));
                pass.add(new Byte((byte)((len >> 8) & 0xff)));
                pass.add(new Byte((byte)((len) & 0xff)));
                pass.add(new Byte((byte)((len) & 0xff)));
                try {
                try {
                        fcpProtocol.send(channelNumber, pass, pass.size());
                        fcpProtocol.send(channelNumber, pass, pass.size());
                        fcpProtocol.sendDataRequest(channelNumber, 20);
                        fcpProtocol.sendDataRequest(channelNumber, 20);
                } catch (FCPException e) {
                } catch (FCPException e) {
                        // TODO Auto-generated catch block
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        e.printStackTrace();
                }
                }
                byte[] bytes = fcpProtocol.getDataResponse();
                byte[] bytes = fcpProtocol.getDataResponse();
                txtResult.clear();
                txtResult.clear();
                txtResult.setText(StringUtil.arrayToHexString(bytes));
                txtResult.setText(StringUtil.arrayToHexString(bytes));
        }
        }
}
}
 
 

powered by: WebSVN 2.1.0

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