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

    笨鸟先飞
  • 相关阅读:
    ubuntu mint 开机启动项管理
    ubuntu mint 15 编译安装PHP开发环境
    cakephp recursive -1,0,1,2 速查
    git revert all changes
    windows环境变量修改立刻生效的办法
    windows7 mysql install
    ubuntu ll命令
    [Matlab]算法工匠视频1:数字信号处理仿真及实现 第一讲 信号源的产生和滤波1、2
    [Maltab]线性卷积、周期卷积及循环(圆周)卷积
    [C++]自编FFT(递归形式)
  • 原文地址:https://www.cnblogs.com/zoutingrong/p/14156779.html
Copyright © 2011-2022 走看看