-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPictureTest.java
More file actions
93 lines (78 loc) · 2.34 KB
/
PictureTest.java
File metadata and controls
93 lines (78 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package IO;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class PictureTest {
//对图片进行加密
@Test
public void test1() {
FileInputStream fi = null;
FileOutputStream fo = null;
try {
fi = new FileInputStream(new File("香港图书馆.jpeg"));
fo = new FileOutputStream(new File("香港图书馆secret.jpeg"));
byte[] buffer = new byte[1024];
int len;
while ((len = fi.read(buffer)) != -1) {
for (int i = 0; i < len; i++) {
buffer[i] = (byte) (buffer[i] ^ 5);
}
fo.write(buffer, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fi != null) {
try {
fi.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fo != null) {
try {
fo.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
//对图片进行解密
@Test
public void test2() {
FileInputStream fi = null;
FileOutputStream fo = null;
try {
fi = new FileInputStream(new File("香港图书馆secret.jpeg"));
fo = new FileOutputStream(new File("香港图书馆Nosecret.jpeg"));
byte[] buffer = new byte[1024];
int len;
while ((len = fi.read(buffer)) != -1) {
for (int i = 0; i < len; i++) {
buffer[i] = (byte) (buffer[i] ^ 5);
}
fo.write(buffer, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fi != null) {
try {
fi.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fo != null) {
try {
fo.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}