⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 input_output.java

📁 一个简单的RSA 实现程序
💻 JAVA
字号:
package SimpleRSA;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Input_Output 
{
	

	static int[] Input_Plain(String args)
	{
		int[] temp = null;
		try
			{
				File file = new File(args);
				byte[] bt = new byte[(int)file.length()];
				FileInputStream in = new FileInputStream(file);
				in.read(bt);
				temp = new int[bt.length];
				for(int i=0;i<bt.length;i++)
						temp[i] = bt[i] + 128;
				in.close();
			}
		catch (IOException e)
			{
				System.out.println("IO Errors: 1");
			}
		return temp;
	}

	static int[] Input_Cipher(String args)
	{
		StringBuffer s = new StringBuffer();
		try
			{
				FileInputStream in = new FileInputStream(new File(args));
				while(in.available()>0)
					{
						s.append((char)in.read());
					}
				in.close(); 
			}
		catch (IOException e)
			{
				System.out.println("IO Errors: 2");
			}
		int Cipher[] = new int[s.length()/3];
		for(int i=0;i<Cipher.length;i++)
			{
				Cipher[i] = Integer.parseInt(s.substring(i*3, (i+1)*3));
			}
		return Cipher;
	}

	static String Input_Key(String args)
	{
		String keyString = "";
		try
			{
				FileInputStream in = new FileInputStream(new File(args));
				while(in.available()>0)
					{
						keyString += (char)in.read();
					}
				in.close(); 
			}
		catch (IOException e)
			{
				System.out.println("IO Errors: 3");
			}
		return keyString;
	}
	
	static byte[] Input_PlainForSign(String args)
	{
		byte[] bt =null;
		try
		{
			File file = new File(args);
			bt = new byte[(int)file.length()];
			FileInputStream in = new FileInputStream(file);
			in.read(bt);
			in.close();
		}
		catch(IOException e)
		{
			System.out.println("IO Errors: 7");
		}
		return bt;
		
	}
	static void Output_Cipher(String args,String s)
	{
		try
			{
				File file = new File(args);
				FileOutputStream out = new FileOutputStream(file);
				byte b[] = new byte[s.length()];
				b=s.getBytes();
				out.write(b);
			}
		catch (IOException e)
			{
				System.out.println("IO Errors: 4");
			}
	}
	
	static void Output_Plain(String args,byte[] plain)
	{
		File file = new File(args);
		FileOutputStream out;
		try
			{
				out = new FileOutputStream(file);
				out.write(plain);
			} 
		catch (IOException e) 
			{
				System.out.println("IO errors: 5");
			}
		
	}
	static void Output_Key(String args,int[] key)
	{
		File file = new File(args);
		String s = "";
		if(key.length == 2)
			{
				s = s + "modular: " + key[0] + (char)13 + (char)10;
				s = s + "public key: " + key[1];
			}
		else
			{
				s = s + "modular: " + key[0] + (char)13 + (char)10;
				s = s + "public key: " + key[1] + (char)13 + (char)10;
				s = s + "private key: " + key[2];
			}
		try
			{
				FileOutputStream out = new FileOutputStream(file);
				byte b[] = new byte[s.length()];
				b=s.getBytes();
				out.write(b);
			}
		catch (IOException e)
			{
				System.out.println("IO Errors: 6");
			}
	}
	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -