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中记录一下,若有错误请见谅。

    笨鸟先飞
  • 相关阅读:
    解决winXP无法远程桌面连到win8
    Exception处理
    Java父类与子类的内存引用讲解
    JAVA子类继承父类
    JAVA子类调用父类构造方法
    JS 矩阵转置
    JS 二分查找
    JS冒泡排序
    JS 求平均值
    关于STM32 NVIC配置的解释
  • 原文地址:https://www.cnblogs.com/zoutingrong/p/14156779.html
Copyright © 2011-2022 走看看