• 大小: 4KB
    文件类型: .java
    金币: 1
    下载: 0 次
    发布日期: 2021-06-11
  • 语言: Java
  • 标签: 单表  加密  java  

资源简介

单表代换加密算法的java实现,仅限于对英文.txt文档的加密

资源截图

代码片段和文件信息


//在计算机中,我们可以将文件分为文本文件(text file)和二进制文件(binary file)两种。
//文本文件中只包含字母、数字、标点及一些特殊字符,这些字符有一个共同点,
//它们最多只有7位有效编码,即使用8位编码格式的字节中最高位为0,
//我们也常将这种文件称为ASCII文件。
//二进制文件中则可以包括任意数据,所以它的数据字节中常常有最高位为1的字节,
//即它的8位字节编码都是有效的。

import java.io.*;

public class Monoalphabetic {
private String srcFilePath;
private String prnPath;

public Monoalphabetic(String filePathString parentPath){
this.srcFilePath = filePath;
this.prnPath = parentPath;
}

public void cipher(){
try{
         File sourceFile = new File(srcFilePath);

         File outFile = new File(prnPath+“\\Monoalphabetic encryption.txt“);
outFile.createNewFile();

//实现方案1:用BufferedReader一个字符一个字符读写
//         BufferedReader in = new BufferedReader(new FileReader(sourceFile));
// BufferedWriter out = new BufferedWriter(new FileWriter(outFile));
//         int inChar;
//         while((inChar=in.read())!=-1){
//         inChar++;
//         out.write(inChar);
//         }
//         in.close();
//         out.close();
        
         //实现方案2:用RandomAccessFile一个字符一个字符读写
//         RandomAccessFile sf = new RandomAccessFile(sourceFile “rw“);
//     RandomAccessFile of = new RandomAccessFile(outFile “rw“);
// char inChar;
// while(sf.getFilePointer()// inChar = sf.readChar();
// of.writeChar(inChar);
// System.out.println(inChar);
//// inChar = sf.readLine(); //或者整行读写,再对String inChar进行操作
//// of.writeChars(inChar+“ “);
// }
// sf.close();
// of.close();
 

//  solution 3: assuming that we only need to access data from .txt files
         RandomAccessFile sf = new RandomAccessFile(sourceFile “r“);
     RandomAccessFile of = new RandomAccessFile(outFile “rw“);


评论

共有 条评论