当前位置:网站首页>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();
}
}
}
}
}
边栏推荐
- shell-运算符
- Solr basic operation
- koa2学习和使用
- Create an API rapid development platform, awesome!
- Halcon practical: design idea of solder joint detection
- Is China Merchants Securities reliable? Is it safe to open a stock account?
- Solr basic operation 2
- 西门子低代码平台通过Database Connector 连接Mysql 实现增删改查
- Applet plug-in access, development and precautions
- Sword finger offer 14- I. cut rope
猜你喜欢

matplotlib matplotlib中plt.hist()参数解释

Halcon实用:焊点检出设计思路

Et la tarte aux framboises 4? Quels sont les jeux possibles?

FPGA Development (2) -- IIC communication

@Scheduled annotation pit, I stepped on it for you

声网自研传输层协议 AUT 的落地实践丨Dev for Dev 专栏

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

云服务器的安全设置常识

Leetcode (680) -- verifying palindrome string II

Sword finger offer 14- ii Cutting rope II
随机推荐
Binary search tree 230 The element with the smallest K in the binary search tree 1038 From binary search tree to larger sum tree
海外数字身份验证服务商ADVANCE.AI入选EqualOcean《2022品牌出海服务市场研究报告》
简单理解B树和B+树
Solr基础操作1
网上开户选哪个证券公司?还有,在线开户安全么?
Dépannage de l'étiquette: impossible d'ouvrir l'image marquée
Matplotlib plt Hist() parameter explanation
Et la tarte aux framboises 4? Quels sont les jeux possibles?
Bee common configuration
AI赋能新零售,「智」胜之道在于生态思维|数智夜话直播精选摘录
Solr基础操作5
History of deep learning
Sword finger offer 15 Number of 1 in binary
按头安利!好看又实用的电机 SolidWorks模型素材看这里
What is online account opening? In addition, is it safe to open a mobile account?
Yunhe enmo, gaiguoqiang, identify it and grasp it before the domestic database boils
Top ten securities companies: "bulldozer market" reappearance
Halcon practical: design idea of solder joint detection
均值、方差、标准差、协方差的概念及意义
[Shangshui Shuo series] day 8