package back;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class Back {
public static void main(String[] args) throws Exception {
//复原格式
FileInputStream inputStream = new FileInputStream("C:\\Users\\Administrator\\Desktop\\PathTest.txt");
InputStreamReader input = new InputStreamReader(inputStream);
BufferedReader buffer = new BufferedReader(input);
String line = "";
String str1 = "";
String str2 = "";
Map<Byte, String> route = new HashMap<Byte, String>();
while ((line = buffer.readLine()) != null){
if (line.indexOf("路径信息")>-1 ){
str1 = line.substring(line.indexOf("[byte=")+6,line.indexOf("];"));
str2 = line.substring(line.indexOf("[path=")+6,line.indexOf(")"));
}
route.put(Byte.parseByte(str1),str2);
}
//拆分密文
FileInputStream inputStream2 = new FileInputStream("C:\\Users\\Administrator\\Desktop\\CodeTest2.txt");
InputStreamReader input2 = new InputStreamReader(inputStream2);
BufferedReader buffer2 = new BufferedReader(input2);
String line2 = buffer2.readLine();
int lenth = str2.length();
int it = line2.length() / lenth;
String[] st = new String[it];
int j = 0;
for (int i = 0; i < line2.length(); i+=lenth) {
st[j++] = line2.substring(i,i+lenth);
}
//翻译
byte[] st2 = new byte[it];
for (Map.Entry<Byte, String> tmp :
route.entrySet()) {
String s = tmp.getValue();
for (int i = 0; i < st.length; i++) {
if (s.equals(st[i])){
st2[i] = tmp.getKey();
}
}
}
FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\output.jpg");
fileOutputStream.write(st2);
fileOutputStream.flush();
fileOutputStream.close();
}
}