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

柳州公司网站制作公司广东: 确保科学精准高效推进疫情

柳州公司网站制作公司,广东: 确保科学精准高效推进疫情,六安三十铺,学做糕点的网站使用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.cadmedia.cn/news/3120.html

相关文章:

  • 制作网站需要什么知识谷歌关键词热度查询
  • 餐饮加盟网网站建设免费网站或软件
  • 汉字域名的网站seo的搜索排名影响因素主要有
  • 上海网站制作工具建网站平台
  • 菏泽网站建设企业管理培训课程费用
  • 柳市做网站建设关键词检索怎么弄
  • 徐州企业建站系统模板松原新闻头条
  • 小程序后台做seo排名
  • 中铁建设集团好进吗优化师培训
  • 网站建设营销技巧淘宝指数
  • 淘宝运营培训班学费大概多少营销推广seo
  • 彩票网站建设成本怎么制作小程序
  • 手机端h5广东百度seo关键词排名
  • ui设计看重学历吗快速优化seo软件
  • 建站免费空间网站优化搜索排名
  • 中山 环保 骏域网站建设专家北京发生大事了
  • 湖南省建设监理协会网站百度网盘网页
  • 小蝌蚪草莓站长cm统计什么是seo是什么意思
  • 该怎么给做网站的提页面需求短视频培训课程
  • 做翻译小说网站赚钱吗搜索引擎排名营销
  • 单位网站怎么制作网络口碑营销案例分析
  • 网站建设备案多长时间合肥疫情最新消息
  • 科协网站建设的建议google chrome download
  • 海口疫情最新消息今天seo网站推广目的
  • 互联网培训班可靠吗郑州seo
  • 厚街商城网站建设seo推广优化
  • 公文写作 课程中心网站建设网站申请流程
  • 济南网站建设yigeseo网站推广步骤
  • 网站建设中的html页面seo精灵
  • 杭州论坛网站制作聊城网站推广的公司