Java写一个文本加密器

本文介绍了作者利用Java的字符串替换功能开发的一个文本加密器。该工具将文本中的字母替换为难以辨识的标点符号,实现加密效果。文章详细讲解了加密和解密的过程,以及在开发过程中遇到的难点,如特殊字符的转义和解密顺序问题。最后提供了完整的源代码供读者参考。
摘要由CSDN通过智能技术生成

暑假日更第1天!O(∩_∩)O

暑假开始啦。我们有一大堆初一的家庭作业,可是管它呢,还是写博客最重要!

从现在开始,我决定每天日更一篇文章!(呵呵,也不一定每天都能做到啦,所以喜欢我的文章,赶紧关注我,这样可以及时地催一催我哦~~~)o(* ̄︶ ̄*)o

最近真没有什么好点子,花那么多时间学习Java却不知道可以开发一个怎样的程序。但是刚好前几天学了Java的“字符串替换”这个知识点,我便突发奇想:能不能写一个工具,把一些单词里的字母替换成令人看不懂的标点符号,然后可以把这些奇怪的符号发给朋友,那个朋友再用这个工具重新替换成字母。这大概就是所谓的加密解密吧!(*^▽^*)

马上开工!先是绞尽脑汁想出一个好听的名字——“WordKey文本加密器”,接着对窗口界面进行简单地设计,最后盯着屏幕敲代码,遇到了好几个bug,上网度娘,最后终于完工了!总共花了大概3天。(完整源代码展示在文末!)


窗口展示


关键代码

// 获取原来的字段
String oldstr = jTextField1.getText();
//开始加密
String newstr = oldstr;

newstr = newstr.replaceAll("a","^[");
newstr = newstr.replaceAll("A","@^[");
newstr = newstr.replaceAll("b","#&");
newstr = newstr.replaceAll("B","@#&");
newstr = newstr.replaceAll("c","*?");
newstr = newstr.replaceAll("C","@*?");
newstr = newstr.replaceAll("d","!(");
newstr = newstr.replaceAll("D","@!(");
newstr = newstr.replaceAll("e","~+");
newstr = newstr.replaceAll("E","@~+");
newstr = newstr.replaceAll("f","!%");
newstr = newstr.replaceAll("F","@!%");
newstr = newstr.replaceAll("g","_)");
newstr = newstr.replaceAll("G","@_)");

//输出新的字段
jTextField2.setText(newstr);

简单讲解以下这段代码,先获取了jTextField1(“原字段”文本字段)中的字符,再将这些字符中的字母通过“字符串替换”的方式,改成几个不容易让别人看出的标点符号,最后输出到jTextField2(“密码段”文本字段)中,完成一整个加密过程。

这里只展示了a~g的字母加密过程(详细过程见文末的“完整代码”展示)。为了确保加密后的英文单词在解密后与原来的单词完全一致,大小写也要区分,所以大写字母比小写字母最后得到的加密结果前面多出了一个“@”。٩(๑>◡<๑)۶

解密过程和加密差不多,只是反了一下(详细过程见文末的“完整代码”展示)。


难点解析

这个程序最大的难点就在于如何解密在加密的时候可以把字母替换成任何标点符号,例如把“a”转换成“^[”这个字符串,这是没有问题的。但是把“@^[”转换回“a”却报了错,经过上网查询才知道这两个标点在Java中有特殊含义,需要在字母前添加转义符“\\”。可哪些标点需要添加转移符呢?最保守的办法是在每个标点符号前加上“\\”,不过我还是一个字母一个字母地试了,花费了不少时间。o(╥﹏╥)o

还遇到的问题就是把大写的“A”转换成“@^[”后,再进行解密,却得到了“@a”。仔细一检查才得知,因为先解密小写字母,再解密大写字母,所以原来是先将“@^[”中的“^[”替换成“a”,在“@a”中没有找到“A”的对应字符串“@^[”,所以输出了“@a”。我得出结论:为了达到预期,应该先解密大写字母,再解密小写字母

(详细bug解析见文末的“完整代码”展示)


完整代码(复制粘贴即可使用)

Start.java(入口类)

package wordkey;

//作者:O.M.G 欧子正
//————————启动器————————
public class Start {
    public static void main(String[] args) {
        WordTo.main();
    }
}

WordTo.java(加密类)

package wordkey;

//作者:O.M.G 欧子正
//————————加密器————————
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.UIManager;

public class WordTo extends javax.swing.JFrame {

    public WordTo() {
        initComponents();
        window();
        makeButton();
    }
    
    private void window() {
        setLocationRelativeTo(null);  //窗口居中
    }
    
    public void makeButton() {
        jLabel4.addMouseListener(new MouseListener() {
          
            public void mouseReleased(MouseEvent e) {}
            public void mousePressed(MouseEvent e) {}
            public void mouseExited(MouseEvent e) {}
            public void mouseEntered(MouseEvent e) {}
            
            public void mouseClicked(MouseEvent e) {
                WordBack.main();
                dispose();
            }
        
        });   
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("WordKey文本加密器v1.3-独特的字母加密工具");
        setFont(new java.awt.Font("等线", 0, 18)); // NOI18N

        jLabel1.setFont(new java.awt.Font("等线", 1, 24)); // NOI18N
        jLabel1.setText("WordKey文本加密器");

        jLabel2.setFont(new java.awt.Font("等线", 0, 18)); // NOI18N
        jLabel2.setText("原字段:");

        jTextField1.setColumns(8);
        jTextField1.setFont(new java.awt.Font("等线", 0, 18)); // NOI18N

        jTextField2.setColumns(8);
        jTextField2.setFont(new java.awt.Font("等线", 0, 18)); // NOI18N

        jLabel3.setFont(new java.awt.Font("等线", 0, 18)); // NOI18N
        jLabel3.setText("密码段:");

        jButton1.setFont(new java.awt.Font("等线", 0, 18)); // NOI18N
        jButton1.setText("加密");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("等线", 0, 14)); // NOI18N
        jLabel4.setForeground(java.awt.Color.blue);
        jLabel4.setText("文本解密");
        jLabel4.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(82, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(9, 9, 9))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jButton1)))
                .addContainerGap(83, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(44, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // 获取原来的字段
        String oldstr = jTextField1.getText();
        
        //自创SSAP加密方式
        //加密规则:(共应用这些英文符号:*~`!#%^&()+=-_[]|{}:;<>?/)
        //a=^[     b=#&     c=*?     d=!(     e=~+     f=!%     g=_)
        //h=`{     i=]>     j=;/     k=)=     l=#-     m=|}     n=<:
        //o=^&     p=#%     q=<`     r=#?     s=_}     t=*>
        //u=%&     v=)-     w=!+     x=~%     y=*`     z=#=
        //所有大写字母在加密后的字段前加上@,例如:a=^[     A=@^[
        
        //【BUG】:d=$%(测试后发现不能加密成$)
        
        //开始加密
        String newstr = oldstr;
        //a=^[     b=#&     c=*?     d=!(     e=~+     f=!%     g=_)
        newstr = newstr.replaceAll("a","^[");
        newstr = newstr.replaceAll("A","@^[");
        newstr = newstr.replaceAll("b","#&");
        newstr = newstr.replaceAll("B","@#&");
        newstr = newstr.replaceAll("c","*?");
        newstr = newstr.replaceAll("C","@*?");
        newstr = newstr.replaceAll("d","!(");
        newstr = newstr.replaceAll("D","@!(");
        newstr = newstr.replaceAll("e","~+");
        newstr = newstr.replaceAll("E","@~+");
        newstr = newstr.replaceAll("f","!%");
        newstr = newstr.replaceAll("F","@!%");
        newstr = newstr.replaceAll("g","_)");
        newstr = newstr.replaceAll("G","@_)");
        //h=`{     i=]>     j=;/     k=)=     l=#-     m=|}     n=<:
        newstr = newstr.replaceAll("h","`{");
        newstr = newstr.replaceAll("H","@`{");
        newstr = newstr.replaceAll("i","]>");
        newstr = newstr.replaceAll("I","@]>");
        newstr = newstr.replaceAll("j",";/");
        newstr = newstr.replaceAll("J","@;/");
        newstr = newstr.replaceAll("k",")=");
        newstr = newstr.replaceAll("K","@)=");
        newstr = newstr.replaceAll("l","#-");
        newstr = newstr.replaceAll("L","@#-");
        newstr = newstr.replaceAll("m","|}");
        newstr = newstr.replaceAll("M","@|}");
        newstr = newstr.replaceAll("n","<:");
        newstr = newstr.replaceAll("N","@<:");
        //o=^&     p=#%     q=<`     r=#?     s=_}     t=*>
        newstr = newstr.replaceAll("o","^&");
        newstr = newstr.replaceAll("O","@^&");
        newstr = newstr.replaceAll("p","#%");
        newstr = newstr.replaceAll("P","@#%");
        newstr = newstr.replaceAll("q","<`");
        newstr = newstr.replaceAll("Q","@<`");
        newstr = newstr.replaceAll("r","#?");
        newstr = newstr.replaceAll("R","@#?");
        newstr = newstr.replaceAll("s","_}");
        newstr = newstr.replaceAll("S","@_}");
        newstr = newstr.replaceAll("t","*>");
        newstr = newstr.replaceAll("T","@*>");
        //u=%&     v=)-     w=!+     x=~%     y=*`     z=#=
        newstr = newstr.replaceAll("u","%&");
        newstr = newstr.replaceAll("U","@%&");
        newstr = newstr.replaceAll("v",")-");
        newstr = newstr.replaceAll("V","@)-");
        newstr = newstr.replaceAll("w","!+");
        newstr = newstr.replaceAll("W","@!+");
        newstr = newstr.replaceAll("x","~%");
        newstr = newstr.replaceAll("X","@~%");
        newstr = newstr.replaceAll("y","*`");
        newstr = newstr.replaceAll("Y","@*`");
        newstr = newstr.replaceAll("z","#=");
        newstr = newstr.replaceAll("Z","@#=");
        
        //输出新的字段
        jTextField2.setText(newstr);
    }                                        

    public static void main() {
        try {
        UIManager.setLookAndFeel(
        UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) { 
        }
        JFrame.setDefaultLookAndFeelDecorated(true); 

        WordTo wordto = new WordTo();
        wordto.setVisible(true);
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration                   
}

WordBack.java(解密类)

package wordkey;

//作者:O.M.G 欧子正
//————————解密器————————
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.UIManager;

public class WordBack extends javax.swing.JFrame {

    public WordBack() {
        initComponents();
        window();
        makeButton();
    }
    
    private void window() {
        setLocationRelativeTo(null);  //窗口居中
    }
    
    public void makeButton() {
        jLabel4.addMouseListener(new MouseListener() {
          
            public void mouseReleased(MouseEvent e) {}
            public void mousePressed(MouseEvent e) {}
            public void mouseExited(MouseEvent e) {}
            public void mouseEntered(MouseEvent e) {}
            
            public void mouseClicked(MouseEvent e) {
                WordTo.main();
                dispose();
            }
        
        });   
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("WordKey文本解密器v1.3-独特的字母解密工具");
        setFont(new java.awt.Font("等线", 0, 18)); // NOI18N

        jLabel1.setFont(new java.awt.Font("等线", 1, 24)); // NOI18N
        jLabel1.setText("WordKey文本解密器");

        jLabel2.setFont(new java.awt.Font("等线", 0, 18)); // NOI18N
        jLabel2.setText("密码段:");

        jTextField1.setColumns(8);
        jTextField1.setFont(new java.awt.Font("等线", 0, 18)); // NOI18N

        jTextField2.setColumns(8);
        jTextField2.setFont(new java.awt.Font("等线", 0, 18)); // NOI18N

        jLabel3.setFont(new java.awt.Font("等线", 0, 18)); // NOI18N
        jLabel3.setText("原字段:");

        jButton1.setFont(new java.awt.Font("等线", 0, 18)); // NOI18N
        jButton1.setText("解密");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("等线", 0, 14)); // NOI18N
        jLabel4.setForeground(java.awt.Color.blue);
        jLabel4.setText("文本加密");
        jLabel4.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(82, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(9, 9, 9))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jButton1)))
                .addContainerGap(83, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(45, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // 获取原来的字段
        String oldstr = jTextField1.getText();
        
        //自创SSAP加密方式
        //加密规则:(共应用这些英文符号:*~`!#%^&()+=-_[]|{}:;<>?/)
        //a=^[     b=#&     c=*?     d=!(     e=~+     f=!%     g=_)
        //h=`{     i=]>     j=;/     k=)=     l=#-     m=|}     n=<:
        //o=^&     p=#%     q=<`     r=#?     s=_}     t=*>
        //u=%&     v=)-     w=!+     x=~%     y=*`     z=#=
        //所有大写字母在加密后的字段前加上@,例如:a=^[     A=@^[
        
        //【BUG】:d=$%(测试后发现不能加密成$)
        
        //开始解密
        String newstr = oldstr;
        
        //【BUG1】正则表达式无效【解决办法】符号前加上转义符\\
        //【BUG2】^有转义功能,会被忽略【解决办法】^前加上转义符\\,使其失去转义作用
        //【BUG3】生成的单个字母,两边总是有c,例如:cac【解决办法】将c的加密符*?全部加上转义符\\,测试成功
        //【BUG4】符号+与【BUG2】同理
        //【BUG5】若将@^[解密,会先将^[部分解密为a,最终得到@a【解决办法】所有大写字母与小写字母的解密命令上下调换位置
        //【BUG6】符号|与【BUG3】同理
        
        //a=^[     b=#&     c=*?     d=!(     e=~+     f=!%     g=_)
        newstr = newstr.replaceAll("@\\^\\[","A");
        newstr = newstr.replaceAll("\\^\\[","a");
        newstr = newstr.replaceAll("@#&","B");
        newstr = newstr.replaceAll("#&","b");
        newstr = newstr.replaceAll("@\\*\\?","C");
        newstr = newstr.replaceAll("\\*\\?","c");
        newstr = newstr.replaceAll("@!\\(","D");
        newstr = newstr.replaceAll("!\\(","d");
        newstr = newstr.replaceAll("@~\\+","E");
        newstr = newstr.replaceAll("~\\+","e");
        newstr = newstr.replaceAll("@!%","F");
        newstr = newstr.replaceAll("!%","f");
        newstr = newstr.replaceAll("@_\\)","G");
        newstr = newstr.replaceAll("_\\)","g");
        
        //h=`{     i=]>     j=;/     k=)=     l=#-     m=|}     n=<:
        newstr = newstr.replaceAll("@`\\{","H");
        newstr = newstr.replaceAll("`\\{","h");
        newstr = newstr.replaceAll("@\\]>","I");
        newstr = newstr.replaceAll("\\]>","i");
        newstr = newstr.replaceAll("@;/","J");
        newstr = newstr.replaceAll(";/","j");
        newstr = newstr.replaceAll("@\\)=","K");
        newstr = newstr.replaceAll("\\)=","k");
        newstr = newstr.replaceAll("@#-","L");
        newstr = newstr.replaceAll("#-","l");
        newstr = newstr.replaceAll("@\\|\\}","M");
        newstr = newstr.replaceAll("\\|\\}","m");
        newstr = newstr.replaceAll("@<:","N");
        newstr = newstr.replaceAll("<:","n");
        
        //o=^&     p=#%     q=<`     r=#?     s=_}     t=*>
        newstr = newstr.replaceAll("@\\^&","O");
        newstr = newstr.replaceAll("\\^&","o");
        newstr = newstr.replaceAll("@#%","P");
        newstr = newstr.replaceAll("#%","p");
        newstr = newstr.replaceAll("@<`","Q");
        newstr = newstr.replaceAll("<`","q");
        newstr = newstr.replaceAll("@#\\?","R");
        newstr = newstr.replaceAll("#\\?","r");
        newstr = newstr.replaceAll("@_\\}","S");
        newstr = newstr.replaceAll("_\\}","s");
        newstr = newstr.replaceAll("@\\*>","T");
        newstr = newstr.replaceAll("\\*>","t");
        
        //u=%&     v=)-     w=!+     x=~%     y=*`     z=#=
        newstr = newstr.replaceAll("@%&","U");
        newstr = newstr.replaceAll("%&","u");
        newstr = newstr.replaceAll("@\\)-","V");
        newstr = newstr.replaceAll("\\)-","v");
        newstr = newstr.replaceAll("@!\\+","W");
        newstr = newstr.replaceAll("!\\+","w");
        newstr = newstr.replaceAll("@~%","X");
        newstr = newstr.replaceAll("~%","x");
        newstr = newstr.replaceAll("@\\*`","Y");
        newstr = newstr.replaceAll("\\*`","y");
        newstr = newstr.replaceAll("@#=","Z");
        newstr = newstr.replaceAll("#=","z");
        
        //输出新的字段
        jTextField2.setText(newstr);
    }                                        

    public static void main() {
        try {
        UIManager.setLookAndFeel(
        UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) { 
        }
        JFrame.setDefaultLookAndFeelDecorated(true); 

        WordBack wordback = new WordBack();
        wordback.setVisible(true);
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration                   
}

感谢阅读

悄悄告诉你,小编是个初中生(具体内容请:点头像看个人简介)。写代码是我的业余爱好,但也占用了我大量的学习时间,不过我仍然深深爱着电脑、爱着键盘、爱着Java、爱着CSDN,也爱着我的一群可爱的读者们。我总会得意又有些傲气地对朋友说:“我是一名专业的程序员”。有时候我也会觉得自己很孤单,因为生活中很少遇到对编程感兴趣的人。但是我的父母我的朋友我的同学们一直陪着我、理解我,与我一起渡过难关。在此,向他们表示由衷的感谢!同时,也感谢我的读者们,你们也一直坚持阅读我的博客,在背后默默支持着我,每回看到阅读量不断蹭蹭地往上涨,我就真正体会到编程的快乐。现在让我对你们说声:谢谢!♪(・ω・)ノ


为了防止走丢,麻烦点个关注吧!这样才能及时看到我的文章哟!如果有什么疑问,欢迎在评论区发言!让我们一起加油!ヾ(◍°∇°◍)ノ゙

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值