当前位置: 首页 > wzjs >正文

学校校园网站建设方案东莞网络公司网络推广

学校校园网站建设方案,东莞网络公司网络推广,网站建设大赛,网站推广策略有哪些使用JAVA-进行维吉尼亚密码的解密与加密-CSDN博客 对上面代码进行改进,并设计了GUI界面 来源于百度百科 维吉尼亚密码_百度百科 运行结果如下: 具体代码: package com.java.MiMa;import javax.swing.*; import java.awt.*; import java.aw…

使用JAVA-进行维吉尼亚密码的解密与加密-CSDN博客

对上面代码进行改进,并设计了GUI界面

来源于百度百科

维吉尼亚密码_百度百科

运行结果如下:

具体代码:

package com.java.MiMa;import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*
明文:ATTACKATDAWN
密钥:LEMONLEMONLE
密文:LXFOPVEFRNHR
解密后:ATTACKATDAWN*/public class WJMYmmGUI extends JFrame {// 常量 26public static final int N = 26;private JTextField plaintextField;private JTextField keyField;private JTextArea ciphertextArea;private JTextArea decryptedtextArea;public WJMYmmGUI() {setTitle("维吉尼亚密码加密解密工具");setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setSize(400, 300);setLayout(new GridLayout(4, 2, 10, 10));setLocationRelativeTo(null);//设置窗体居中// 明文输入部分JLabel plaintextLabel = new JLabel("请输入需要操作的文字:");plaintextField = new JTextField();add(plaintextLabel);add(plaintextField);// 密钥输入部分JLabel keyLabel = new JLabel("请输入密钥:");keyField = new JTextField();add(keyLabel);add(keyField);// 加密按钮和密文显示部分JButton encryptButton = new JButton("加密");ciphertextArea = new JTextArea();//密文显示ciphertextArea.setEditable(false);//设置不可编辑encryptButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {String plaintext = plaintextField.getText().toUpperCase();//读取需要操作的文字,toUpperCase是大写,toLowerCase是小写String key = keyField.getText().toUpperCase();//读取密钥//将待处理文字与密钥去除空格plaintext = plaintext.replace(" ", "").toUpperCase();key = key.replace(" ", "").toUpperCase();if(key.length() != plaintext.length()){//判断密钥长度是否与明文长度相同JOptionPane.showMessageDialog(WJMYmmGUI.this, "密钥长度必须与明文长度相同!", "错误", JOptionPane.ERROR_MESSAGE);return;}String ciphertext = encrypt(plaintext, key);//进行加密ciphertextArea.setText(ciphertext);//设置加密结果显示}});add(encryptButton);add(new JScrollPane(ciphertextArea));// 解密按钮和解密结果显示部分JButton decryptButton = new JButton("解密");decryptedtextArea = new JTextArea();decryptedtextArea.setEditable(false);//设置不可编辑decryptButton.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {String plaintext = plaintextField.getText().toUpperCase();//读取需要操作的文字String key = keyField.getText().toUpperCase();//读取密钥//将待处理文字与密钥去除空格plaintext = plaintext.replace(" ", "").toUpperCase();key = key.replace(" ", "").toUpperCase();if(key.length() != plaintext.length()){//判断密钥长度是否与明文长度相同JOptionPane.showMessageDialog(WJMYmmGUI.this, "密钥长度必须与明文长度相同!", "错误", JOptionPane.ERROR_MESSAGE);return;}String decryptedtext = decrypt(plaintext, key);//进行解密decryptedtextArea.setText(decryptedtext);//设置解密结果显示}});add(decryptButton);add(new JScrollPane(decryptedtextArea));setVisible(true);//设置窗体可见}// 构建加密矩阵private char[][] buildEncryptionMatrix() {String ZM = "abcdefghijklmnopqrstuvwxyz";char[] zm = ZM.toCharArray();char[][] zmb = new char[N][N];for (int i = 0; i < N; i++) {for (int j = 0; j < N; j++) {zmb[i][j] = (char) (zm[j] + i);if (zmb[i][j] >= 'a' && zmb[i][j] <= 'z') {zmb[i][j] = (char) (zmb[i][j] - 32);} else {zmb[i][j] = (char) (zmb[i][j] - N);zmb[i][j] = (char) (zmb[i][j] - 32);}}}return zmb;}// 加密方法private String encrypt(String plaintext, String key) {char[][] zmb = buildEncryptionMatrix();char[] mw = plaintext.toCharArray();char[] k = key.toCharArray();char[] miw = new char[mw.length];for (int i = 0; i < mw.length; i++) {int h = k[i % k.length] - 65;int l = mw[i] - 65;miw[i] = zmb[h][l];}return new String(miw);}// 解密方法private String decrypt(String ciphertext, String key) {char[][] zmb = buildEncryptionMatrix();char[] miw = ciphertext.toCharArray();char[] k = key.toCharArray();char[] jm = new char[miw.length];for (int i = 0; i < miw.length; i++) {int h = k[i % k.length] - 65;for (int j = 0; j < N; j++) {if (zmb[h][j] == miw[i]) {jm[i] = zmb[0][j];break;}}}return new String(jm);}public static void main(String[] args) {new WJMYmmGUI();}
}

http://www.dtcms.com/wzjs/246495.html

相关文章:

  • 上栗网站建设站长工具麻豆
  • 短视频seo排名加盟seo还能赚钱吗
  • qq小程序权限设置石家庄seo按天扣费
  • 多语言做网站软文发布平台排名
  • 高端网站建设品牌郑州网站建设七彩科技
  • 广州市网站制作seo外链发布技巧
  • java做网站好还是asp好百度搜一搜
  • 工程规范查询网深圳市seo网络推广哪家好
  • 网站建设全套教程发布软文网站
  • 做的网站怎样更新线上推广具体应该怎么做
  • 企业年金退休后如何领取整站排名优化公司
  • 太原建站模板源码万能软文范例800字
  • 家具家居网站建设专门代写平台
  • 长沙有哪些大公司沈阳关键词快照优化
  • 自己做的网站403seo具体怎么优化
  • 长沙有做网站的吗南宁seo外包要求
  • 网站上滚动条怎么做百度搜索推广的定义
  • 个人网站可以做企业宣传福州短视频seo网站
  • 访链家网网站开发免费网站建设哪家好
  • 食品网站app建设搜狗网址大全
  • 商机互联做网站怎么样免费网络推广软件
  • 网站链接视频怎么做西安网站搭建公司
  • 洛阳网站建设内容富阳seo关键词优化
  • 湖南郴州市旅游景点阳西网站seo
  • 加工平台苏州纳米所福州网seo
  • 专业做室内设计的网站有哪些方面百度账号怎么注册
  • 秦皇岛海港区疫情最新消息百度seo优化系统
  • 菏泽网站建设推广河北电子商务seo
  • 重庆网站运营公司软文发稿
  • 客户端建站微信投放广告多少钱