zoukankan      html  css  js  c++  java
  • 实现图片加密

    //coding=utf8
     2 /**
     3  * @Author: Sir
     4  * @Created Time : 2020年12月18日 星期五 19时37分56秒
     5  * @File Name: imagesecret.java
     6  * @Description:java基础
     7  * @Mail:1198875194@qq.com
     8  */
     9 import java.io.*;
    10 
    11 public class imagesecret{
    12     public static void main(String[] args){
    13         FileInputStream filer= null;
    14         FileOutputStream filew = null;
    15         try{
    16             filer = new FileInputStream("1.png");
    17             filew = new FileOutputStream("3.png");
    18             byte[] bbuf = new byte[1024];                           
    19             int len;
    20             while((len = filer.read()) != -1){
    21                 //对字节数据进行修改进行加密
    22                 for(int i = 0;i < len;i++){
    23                     bbuf[i] = (byte)(bbuf[i] ^ 5);
    24                 }
    25                 filew.write(bbuf,0,len);
    26             }
    27         }
    28         catch(IOException e){
    29             e.printStackTrace();
    30         }
    31         finally{
    32             if(filer != null){
    33                 try{
    34                     filer.close();
    35                 }
    36                 catch(IOException e){
    37                     e.printStackTrace();
    38                 }
    39             }
    40             if(filew != null){
    41                 try{
    42                     filer.close();
    43                 }
    44                 catch(IOException e){
    45                     e.printStackTrace();
    46                 }
    47             }
    48         }
    49     }
    50 }
    ~                                      

    图片的解密

    //coding=utf8                                                       
     2 /**
     3  * @Author: Sir
     4  * @Created Time : 2020年12月18日 星期五 19时48分48秒
     5  * @File Name: imagedeciphering.java
     6  * @Description:java基础
     7  * @Mail:1198875194@qq.com
     8  */
     9 
    10 import java.io.*;
    11 
    12 public class imagedeciphering{
    13     public static void main(String[] args){
    14         FileInputStream filer= null;
    15         FileOutputStream filew = null;
    16         try{
    17             filer = new FileInputStream("3.png");
    18             filew = new FileOutputStream("4.png");
    19             byte[] bbuf = new byte[1024];
    20             int len;
    21             while((len = filer.read()) != -1){
    22                 //对字节数据进行修改进行解密
    23                 for(int i = 0;i < len;i++){
    24                     bbuf[i] = (byte)(bbuf[i] ^ 5);
    25                 }
    26                 filew.write(bbuf,0,len);
    27             }
    28         }
    29         catch(IOException e){
    30             e.printStackTrace();
    31         }
    32         finally{
    33             if(filer != null){
    34                 try{
    35                     filer.close();
    36                 }
    37                 catch(IOException e){
    38                     e.printStackTrace();
    39                 }
    40             }
    41             if(filew != null){
    42                 try{
    43                     filer.close();
    44                 }
    45                 catch(IOException e){
    46                     e.printStackTrace();
    47                 }
    48             }
    49         }
    50     }
    51 }

    在学习java中记录一下,若有错误请见谅。

    笨鸟先飞
  • 相关阅读:
    C++学习9 this指针详解
    福建省第八届 Triangles
    UVA 11584 Partitioning by Palindromes
    POJ 2752 Seek the Name, Seek the Fame
    UVA 11437 Triangle Fun
    UVA 11488 Hyper Prefix Sets (字典树)
    HDU 2988 Dark roads(kruskal模板题)
    HDU 1385 Minimum Transport Cost
    HDU 2112 HDU Today
    HDU 1548 A strange lift(最短路&&bfs)
  • 原文地址:https://www.cnblogs.com/zoutingrong/p/14156779.html
Copyright © 2011-2022 走看看