假设值为:
int p=9; // (any odd no)
int q=5; // (any odd no)
int e=3;
int n=p*q;
我通过以下代码读取文本文件并将内容转换为字节数组:
while ((eof_line = br.readLine()) != null) {
byte_array = eof_line.getBytes();
String decoded = new String(byte_array, "UTF-8");
// pow=byte_array.to;
for (i = 0; i < byte_array.length; i++) {
double input = byte_array[i];
double t1 = Math.pow(e, -1);
double t2 = n % 2;
double encrypt = (Math.pow(input, e)) * t2;//formula
double p_k = t1 * t2;
double decrypt = (Math.pow(en, p_k)) * t2;//formula
}}
这里我的输入是byte [],解密的值是double.So我想将decrypt(double)转换为原始文本文件内容。怎么办?
答案 0 :(得分:0)
终于......我找到了解决方案..
public String[] OpenFile() throws IOException {
sp1.setVisible(true);
String k = t2.getText();
e = Integer.valueOf(k);
d = (Math.pow(e, -1)) * (n % 2);
System.out.println("d=" + d);
FileReader fr = new FileReader(path);
BufferedReader br = new BufferedReader(fr);
String eof_line;
int numberOfLines = 0;
while ((eof_line = br.readLine()) != null) {
arr = eof_line.toCharArray();
byte_array = eof_line.getBytes();
for (i = 0; i < byte_array.length; i++) {
ta1.append(Integer.toString(byte_array[i]));
double input = byte_array[i];
double t1 = Math.pow(e, -1);
double t2 = n % 2;
double en = (Math.pow(input, e)) * t2;
p_key = t1 * t2;
double de = (Math.pow(en, p_key)) * t2;
b = (char) java.lang.Math.round(de);
ta2.append("" + b);
}
br.close();
return null;
}