?? cryption.java
字號(hào):
package SimpleRSA;
import java.math.BigInteger;
public class Cryption
{
int[] Load_key(String args)
{
String keyfile = Input_Output.Input_Key(args);
int[] key = new int[2];
int i;
i = keyfile.indexOf('p');
key[0] = Integer.parseInt(keyfile.substring(9, i-2));
i = keyfile.lastIndexOf(':');
key[1] = Integer.parseInt(keyfile.substring(i+2,keyfile.length()));
return key;
}
void encrypt(String args1,String args2,String args3)
{
//input plaintext
int[] plain = Input_Output.Input_Plain(args1);
StringBuffer cipher=new StringBuffer();
//load keys
int key[] = new int[2];
key = Load_key(args3);
//encryption
BigInteger subplain[] = new BigInteger[plain.length];
for (int i=0;i<subplain.length;i++)
{
subplain[i] = BigInteger.valueOf(plain[i]);
subplain[i] = subplain[i].pow(key[1]);
subplain[i] = subplain[i].mod(BigInteger.valueOf(key[0]));
if(subplain[i].intValue()>99)
cipher.append(subplain[i]);
else if(subplain[i].intValue()>9)
cipher.append("0").append(subplain[i]);
else
cipher.append("00").append(subplain[i]);
}
//generate encrypted file
Input_Output.Output_Cipher(args2, cipher.toString());
}
void decrypt(String args1,String args2,String args3)
{
//input cipher
int[] cipher = Input_Output.Input_Cipher(args1);
byte plain[] = new byte[cipher.length];
//load keys
int key[] = new int[2];
key = Load_key(args3);
//decryption
BigInteger subcipher[] = new BigInteger[cipher.length];
for (int i=0;i<subcipher.length;i++)
{
subcipher[i] = BigInteger.valueOf(cipher[i]);
subcipher[i] = subcipher[i].pow(key[1]);
subcipher[i] = subcipher[i].mod(BigInteger.valueOf(key[0]));
plain[i] = (byte) (subcipher[i].intValue() - 128);
}
//generate decrypted file
Input_Output.Output_Plain(args2, plain);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -