import java.io.*;
import java.util.*;
class inFile{
String passNum = "abcdefg";
int j = 0;
int i = 0;
public void fileEncription() {
try{
FileInputStream fis = new FileInputStream("C:\\Users\\pc\\Desktop\\1.txt");
FileOutputStream fos = new FileOutputStream("C:\\Users\\pc\\Desktop\\2.txt");
int b;
while((b = fis.read()) != -1) {
b = (int) (b ^ 7);
if(j == passNum.length()) {
j = 0;
}
b = b + passNum.charAt(j);
j++;
fos.write(b);
}
fis.close();
fos.close();
System.out.println("加密完成!");
}catch(IOException e) {
System.out.println("找不到指定文件!");
}
}
public void InEncryption(){
try{
FileInputStream fis1 = new FileInputStream("C:\\Users\\pc\\Desktop\\2.txt");
FileOutputStream fos1 = new FileOutputStream("C:\\Users\\pc\\Desktop\\3.txt");
int b;
while((b = fis1.read()) != -1) {
if(i == passNum.length()) {
i = 0;
}
b = b - passNum.charAt(i);
b = (int) (b ^ 7);
i++;
fos1.write(b);
}
fis1.close();
fos1.close();
System.out.println("解密完成!");
}catch(Exception e){
System.out.println("找不到指定文件!");
}
}
}
public class Encryption extends inFile{
public static void main(String args[]) {
inFile in = new inFile();
System.out.println("1:加密");
System.out.println("2:解密");
int n = new Scanner(System.in).nextInt();
if(n == 1) {
in.fileEncription();
}else if(n == 2) {
in.InEncryption();
}else {
System.out.println("输入错误!");
}
}
}
import java.util.*;
class inFile{
String passNum = "abcdefg";
int j = 0;
int i = 0;
public void fileEncription() {
try{
FileInputStream fis = new FileInputStream("C:\\Users\\pc\\Desktop\\1.txt");
FileOutputStream fos = new FileOutputStream("C:\\Users\\pc\\Desktop\\2.txt");
int b;
while((b = fis.read()) != -1) {
b = (int) (b ^ 7);
if(j == passNum.length()) {
j = 0;
}
b = b + passNum.charAt(j);
j++;
fos.write(b);
}
fis.close();
fos.close();
System.out.println("加密完成!");
}catch(IOException e) {
System.out.println("找不到指定文件!");
}
}
public void InEncryption(){
try{
FileInputStream fis1 = new FileInputStream("C:\\Users\\pc\\Desktop\\2.txt");
FileOutputStream fos1 = new FileOutputStream("C:\\Users\\pc\\Desktop\\3.txt");
int b;
while((b = fis1.read()) != -1) {
if(i == passNum.length()) {
i = 0;
}
b = b - passNum.charAt(i);
b = (int) (b ^ 7);
i++;
fos1.write(b);
}
fis1.close();
fos1.close();
System.out.println("解密完成!");
}catch(Exception e){
System.out.println("找不到指定文件!");
}
}
}
public class Encryption extends inFile{
public static void main(String args[]) {
inFile in = new inFile();
System.out.println("1:加密");
System.out.println("2:解密");
int n = new Scanner(System.in).nextInt();
if(n == 1) {
in.fileEncription();
}else if(n == 2) {
in.InEncryption();
}else {
System.out.println("输入错误!");
}
}
}