当前位置:网站首页>Buffer flow exercise
Buffer flow exercise
2022-06-29 23:54:00 【Small size brother】
1、 Use IO Stream encrypts and decrypts pictures
public class PicTest {
// Image encryption : XOR the picture
@Test
public void test(){
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("bird.png");
fos = new FileOutputStream("bird-secret.png");
byte[] buffer = new byte[20];
int len;
while((len = fis.read(buffer))!=-1){
// Modify the byte array
for(int i=0;i<len; i++){
buffer[i] = (byte) (buffer[i] ^ 5);
}
fos.write(buffer,0,len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if(fos!=null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fis!=null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
// Picture decryption : XOR operation of XOR on pictures
@Test
public void test01(){
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream("bird-secret.png");
fos = new FileOutputStream("bird4.png");
byte[] buffer = new byte[20];
int len;
while((len = fis.read(buffer))!=-1){
// Modify the byte array
for(int i=0;i<len; i++){
buffer[i] = (byte) (buffer[i] ^ 5);
}
fos.write(buffer,0,len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if(fos!=null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fis!=null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
The encrypted picture cannot be opened 
2、 Calculate the number of characters in the text file , And output the results to a text file
/* 1、 Traverse every character of the text
* 2、 Number of occurrences of word exists Map in
* Map<Character,Integer> map = new HashMap<Character,Integer>();
* map.put('a',18)
* map.put(' you ‘,2)
* 3、 take map The data in is written to a file
* /
public class WordCount {
@Test
public void testWordCount(){
FileReader fr = null;
BufferedWriter bw = null;
try {
//1、 establish Map aggregate
Map<Character,Integer> map = new HashMap<>();
//2、 Traverse every character , The number of occurrences of each character map in
fr = new FileReader("Hello.txt");
int c = 0;
while((c= fr.read())!=-1){
//int Restore char
char ch = (char) c;
// Judge char Whether in map For the first time
if(map.get(ch)==null){
map.put(ch,1);
}else {
map.put(ch,map.get(ch)+1);
}
}
//3、 hold map The data in exists in the file count.txt
//3.1、 establish Writer
bw = new BufferedWriter(new FileWriter("helloCount.txt"));
//3.2、 Traverse map, Write data again
Set<Map.Entry<Character,Integer>> entrySet = map.entrySet();
for(Map.Entry<Character,Integer> entry : entrySet){
switch (entry.getKey()){
case ' ':
bw.write(" Space ="+entry.getValue());
break;
case '\t':
bw.write("tab key ="+entry.getValue());
break;
case '\r':
bw.write(" enter ="+entry.getValue());
break;
case '\n':
bw.write(" Line break ="+entry.getValue());
break;
default:
bw.write(entry.getKey()+"="+entry.getValue());
}
bw.newLine();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if(bw!=null){
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fr!=null){
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
边栏推荐
- Fund information disclosure
- Matplotlib histogram of Matplotlib visualization plt bar()
- Remember the process of checking online MySQL deadlock. You should not only know curd, but also know the principle of locking
- Gradle连载7-配置签名
- Collection! Have you ever used these tools to improve programmer productivity?
- Sword finger offer 14- I. cut rope
- 深度学习的历史
- 6.28 problem solving
- Head on Amway! Good looking and practical motor SolidWorks model material see here
- 剑指 Offer 13. 机器人的运动范围
猜你喜欢

Binary search tree 230 The element with the smallest K in the binary search tree 1038 From binary search tree to larger sum tree

AI empowers new retail, the way to win "wisdom" lies in ecological thinking | selected excerpts from digital intelligence night talk live broadcast

333333333333333333333333333333

Overseas digital authentication service provider advance AI was selected into the "2022 brand sea Service Market Research Report" of equalocean

大厂试水 HPE推出Arm CPU通用服务器产品

6.29 problem solving

Yunhe enmo Guoqiang, identifiez - le, saisissez - le, avant l'ébullition de la base de données nationale

穿越过后,她说多元宇宙真的存在

Why is JSX syntax so popular?

C pointer advanced 2-- > function pointer array callback function simplifies calculator code, and implements qsort function based on callback function simulation
随机推荐
Solr basic operation 2
声网自研传输层协议 AUT 的落地实践丨Dev for Dev 专栏
Software testing interface testing JMeter 5.5 installation tutorial
Incluxdb time series database system
6.29日刷题题解
Simple understanding of B tree and b+ tree
Leetcode 1385. Distance value between two arrays
Leetcode (680) -- verifying palindrome string II
matplotlib matplotlib中plt.hist()参数解释
西门子低代码 9.14版本: 满足不同需求
Matplotlib histogram of Matplotlib visualization plt bar()
333333333333333333333333333333
Top ten securities companies: "bulldozer market" reappearance
请指教什么是在线开户?另外,手机开户安全么?
新钛云服荣膺“2022爱分析 · IT运维厂商全景报告”云管理平台CMP 代表厂商!...
Cacti maximum monitoring number test
除子
Which securities company should I choose to open an account online? Also, is it safe to open an account online?
Yunhe enmo Guoqiang, identifiez - le, saisissez - le, avant l'ébullition de la base de données nationale
绿树公司官方网站