南邮大作业----文本处理与加密软件
来源:互联网 发布:河南网络危机公关 编辑:程序博客网 时间:2024/06/07 22:02
(一)课题内容
文本处理与加密软件要求首先把一个文本中满足特定特征的文本提取出来,然后对提取出来的文本进行加密处理。
(二)课题要求
(1)设计满足特征的文本的文法;
(2)词法分析模块结构清晰,可以借助Lex或JavaCC、Antlr等工具自动生成词法分析程序;
(3)选择某种加密算法对所提取的文本进行加密;
(4)界面美观。
这里我们采用hanlp的汉语言处理包http://hanlp.linrunsoft.com/
hanlp中文分词后还提供了关键字提取的功能(基于textrank),一般关键字采用tf-idf算法或者textrank,其中textrank可以在单文本中使用
使用Hanlp需要导入jar包和依赖数据集,并在src下提供配置文件
编码和解码采用的是Base64,Base64并不算是加密算法,只能算是编码算法,不过这里足够用了。
本程序所使用的jar包如下:hanlp-1.2.8 jar ,common-codec-1.8 jar ,JTattoo-1.611 jar
show.java
import java.awt.Container;import java.awt.Font;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.UIManager;public class show extends JFrame implements ActionListener{JMenuBar menuBar;JMenu menu,menu2;JMenuItem menuitem,menuitem2,menuitem3,menuitem4,menuitem5;JTextArea jta;public show(){setTitle("我的关键字加密软件");setLayout(null);setBounds(800,200,400,500); Container container=getContentPane(); menuBar=new JMenuBar();setJMenuBar(menuBar);menu=new JMenu("开始");menuBar.add(menu);menuitem=new JMenuItem("读取文件"); menu.add(menuitem); menuitem.addActionListener(this);menuitem2=new JMenuItem("获得关键字"); menu.add(menuitem2); menuitem2.addActionListener(this);menuitem3=new JMenuItem("加密文件"); menu.add(menuitem3); menuitem3.addActionListener(this);menuitem5=new JMenuItem("解密文件"); menu.add(menuitem5); menuitem5.addActionListener(this);menu2=new JMenu("退出");menuBar.add(menu2);menuitem4=new JMenuItem("退出"); menu2.add(menuitem4); menuitem4.addActionListener(this);jta=new JTextArea();jta.setBounds(15,20,350,380);jta.setLineWrap(true); //激活自动换行功能 jta.setWrapStyleWord(true); // 激活断行不断字功能jta.setFont(new Font("微软雅黑",0,15));JScrollPane jsp = new JScrollPane(jta); jsp.setBounds(15,20,350,380); container.add(jsp);setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent e){ if (e.getSource()==menuitem) { String s=my_filechooser.filechooser(); try {jta.setText(Helper.Read(s));} catch (IOException e1) {System.out.println("打开文件失败");e1.printStackTrace();} } if (e.getSource()==menuitem2) { String s=jta.getText(); jta.setText(Helper.getKeyWord(s)); } if (e.getSource()==menuitem3) { String s=jta.getText(); jta.setText(Helper.commonsEnCodesBase64(s)); } if (e.getSource()==menuitem4) { System.out.println("4"); System.exit(1); } if (e.getSource()==menuitem5) { String s=jta.getText(); jta.setText(Helper.commonsDeCodesBase64(s)); } }public static void main(String[] args) {try { UIManager.setLookAndFeel("com.jtattoo.plaf.mint.MintLookAndFeel"); show s=new show(); } catch (Exception ex) { ex.printStackTrace(); } } }
my_filechooser.java
import java.io.File;import javax.swing.JFileChooser;import javax.swing.JLabel;public class my_filechooser { public static String filechooser(){ JFileChooser jfc=new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES ); jfc.showDialog(new JLabel(), "选择"); jfc.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { //设定可用的文件的后缀名 if(f.getName().endsWith(".txt")||f.isDirectory()){ return true; } return false; } public String getDescription() { return "以txt结尾"; } }); File file=jfc.getSelectedFile(); if(file.isDirectory()){ System.out.println("文件夹:"+file.getAbsolutePath()); }else if(file.isFile()){ System.out.println("文件:"+file.getAbsolutePath()); } return file.getAbsolutePath(); } }
Helper.java
import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.List;import org.apache.commons.codec.binary.Base64;import com.hankcs.hanlp.HanLP;public class Helper { public static String Read(String path)throws IOException { BufferedReader br=null; String content=""; try{ br=new BufferedReader(new FileReader(path)); String line=null; while((line=br.readLine())!=null){ content=content+line; } }finally{ if (br!=null){ br.close(); } } return content; } public static String commonsEnCodesBase64(String content){//编码 byte[] encodeBytes=Base64.encodeBase64(content.getBytes()); return new String(encodeBytes); } public static String commonsDeCodesBase64(String content){//解码 byte[] decodeBytes=Base64.decodeBase64(content.getBytes()); return new String(decodeBytes); } public static String getKeyWord(String s){ List<String> keywordList = HanLP.extractKeyword(s,1); return keywordList.get(0); } }
提取关键字:
加密:
解密:
阅读全文
0 0
- 南邮大作业----文本处理与加密软件
- 软件注册与加密
- 加密与解密小软件
- 特征工程与文本处理
- 特征工程与文本处理
- 自然语言处理与文本检索
- 自然语言处理课程作业 中文文本情感分类
- 自然语言处理课程作业 中文文本情感分类
- 文本加密
- 加密.文本.
- 文本加密
- 软件开发竞赛与协同作业
- 软件注册与加密(2)
- 软件注册与加密(1)
- awk语法与文本应用处理
- awk语法与文本应用处理
- 正则表达式与文本格式化处理
- linux基本命令-文本过滤与处理
- CMarkup类的成员函数
- Angular.js中使用$watch监听模型变化
- python打开windows应用程序
- 基于事件驱动的并发编程
- centos6/7 安装rabbitmq
- 南邮大作业----文本处理与加密软件
- 链表中倒数第K个结点
- SSD 之WL磨损平衡
- mycat入门教程
- Ubuntu下安装CodeBlocks的正确姿势
- 端口转发工具lcx使用两类
- 《Java编程思想》学习笔记6——文件和目录常用操作
- JVM&GC Full Coverage
- 百度Ueditor的上传附件图标路径及有些文件的图标不对问题