图片加密算法

2016-08-22 热点事件 阅读:

图片加密算法(一)
DES加密图片算法实现

/********************************************************************

created: 2010/04/18

file base: des_ult

file ext: cpp

author: Terry

purpose: demo DES encrypt system

notice: 使用时必须保证运行目录下有需要加密的文件plaintext.txt

此程序在VC++ 6.0下调试通过!

有问题请邮件至:Terryhy520@gmail.com

*********************************************************************/

#include<iostream.h>

#include<cstring>

#include<fstream.h>

#include<windows.h>

#include<stdio.h>

#define Null 0

#define htonl(a) ((((a) & 0XFF000000) >> 24) | (((a) & 0X00FF0000) >> 8) | \

(((a) & 0X0000FF00) << 8) | (((a) & 0X000000FF) << 24))

typedef int (*MsgHandler) (void);

struct MessageMapEntry {

char ch;

MsgHandler handler;

};

/*版权及作者信息*/

int about() {

cout<<"*********************************************"<<endl;

cout<<"*** by Terry ***"<<endl;

cout<<"*** copyright 2010,All rights reserved by ***"<<endl;

cout<<"*** Terry,technology supported by weizuo !***"<<endl;

cout<<"*** If you have any question, please mail ***"<<endl;

cout<<"*** to 18679376@qq.com ! ***"<<endl;

cout<<"*** Computer of science and engineering ***"<<endl;【图片加密算法】

cout<<"*** XiDian University 2010-4-18 ***"<<endl;

cout<<"*********************************************"<<endl;

cout<<endl<<endl<<endl;

return 0;

}

// 初始置换

int InitialPermute[]={58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4, 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8, 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3, 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7};

// 置换选择PC1

int PermuteChoice1[]={57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4};

// 置换选择PC2

int PermuteChoice2[]={14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32}; // 扩充置换E

int ExpandPermute[]={32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13, 14, 15, 16, 17, 16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25, 24, 25, 26, 27, 28, 29, 28, 29, 30, 31, 32, 1};

// 对左移次数的规定

int shiftnum[]={1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1};

// 输入64位密钥

int key64[]={0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1};

// 置换函数P

int PermuteFunction[]={16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25};

// 逆初始置换

int ReverseIP[]={40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31, 38, 6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29, 36, 4, 44, 12, 52, 20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27, 34, 2, 42, 10, 50, 18, 58, 26, 33, 1, 41, 9, 49, 17, 57, 25};

// S盒

int Sbox[8][4][16]=

{{{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7},

{0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8},

{4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0},

{15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13}},

【图片加密算法】

{{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10},

{3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5},

{0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15},

{13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9}},

{{10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8},

{13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1},

{13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7},

{1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12}},

{{7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15},

{13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9},

{10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4},

{3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14}},

{{2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9},

{14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6},

{4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14},

{11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3}},

{{12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11},

{10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8},

{9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6},

{4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13}},

{{4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1},

{13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6},

{1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2},

{6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12}},

{{13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7},

{1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2},

{7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8},

{2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}}};

int key48[16][48];

//将字符转化为二进制数组

int charToBinary(char * chin, int iaout[])

{

int temp1 = *(int *)chin;

int temp2 = *(int *)(chin+4);

temp1 = htonl(temp1);

temp2 = htonl(temp2);

int i;

for(i = 0; i < 32; i++)

{

iaout[31-i] = ((temp1>>i)&0x01);

iaout[63-i] = ((temp2>>i)&0x01);

}

return 0;

}

//将二进制数组转化为字符

int binaryToChar(int iain[], char * chout)

{

int i;

int *temp[2];

}

temp[0] = (int *)chout; temp[1] = (int *)(chout+4); for(i = 0; i < 32; i++) { *temp[0]= (*temp[0]<<1)+iain[i]; *temp[1]= (*temp[1]<<1)+iain[32+i]; } *temp[0] = htonl(*temp[0]); *temp[1] = htonl(*temp[1]); return 0;

//从新初始化字符数组

int resetChar(char cain[], int inlength)

{

for(int i = 0; i < inlength; i++)

{

cain[i] = '\0';

}

return 0;

}

/*向屏幕输出数组*/

void display(int table[],int n,int row) {

int i, m = 1;

for(i=0; i<n; i++,m++) {

cout<<table[i]<<" ";

if(m == row) {

cout<<endl;

m = 0;

}

}

cout<<endl;

}

/*选择置换1,将64位密钥选择成56位*/

void permute_option1(int tablein[], int tableout[]) {

for(int i=0; i<56; i++) {

tableout[i] = tablein[PermuteChoice1[i]-1];

}

}

/*将一个数组拆分成两个数组*/

void division(int tablein[], int tableout1[], int tableout2[], int n) { for(int i=0; i<n; i++) {

tableout1[i] = tablein[i];

tableout2[i] = tablein[i+n];

}

}

/*将数组左移n位*/

void left_shift(int table[], int n) {

int i;

int temp[28];

for (i=0; i<28-n; i++) {

temp[i] = table[i+n];

}

for (i=0; i<n; i++) {

temp[28-n+i] = table[i];

}

for (i=0; i<28; i++) {

table[i] = temp[i];

}

}

/*将两个数组合并成一个数组*/

void mergence(int tablein1[], int tablein2[], int tableout[], int n) { for(int i=0; i<n; i++) {

tableout[i] = tablein1[i];

tableout[i+n] = tablein2[i];

}

}

/*置换选择2,从56位密钥中选出48位*/

void permute_option2(int tablein[], int tableout[48]) { for(int i=0; i<48; i++) {

tableout[i] = tablein[PermuteChoice2[i]-1]; }

}

/*产生16轮的密钥,存放在key48[16]数组中*/

void produce_key () {

int c28[28], d28[28];

int key56[56];

permute_option1(key64, key56);

division(key56, c28, d28, 28);

for(int i=0; i<16; i++) {

left_shift(c28, shiftnum[i]);

left_shift(d28, shiftnum[i]);

mergence(c28, d28, key56, 28);

permute_option2(key56, key48[i]);

图片加密算法(二)
数字图像加密算法研究与实现

海 南 大 学

毕 业 论 文(设计)

题 目:数字图像加密算法研究与实现

学 号:

姓 名:

年 级:二

学 院:信息科学技术学院【图片加密算法】

系 别:通

专 业:通

指导教师:

完成日期: 零 一 零 级 信 工 程 系 信 工 程 2014 年 5月 1 日

摘 要

近十年来,随着信息网络技术的飞速发展,多媒体技术在各领域的应用可谓是日新月异。数字图像无疑已经成为互联网的主要交互对象之一。数字图像在军事系统、政府机构、医疗系统、国防系统和金融系统等重要机构中得到了广泛应用,这也意味着图像在传输的过程中存在着巨大的安全隐患。若在传输的时候被第三方恶意的拦截、随意篡改、非法拷贝、任意传播,后果将会很严重。所以数字图像的安全传输问题,受到了大众的普遍重视。因此信息安全已成为人们关心的焦点,也是当今的研究热点和难点。 为了实现数字图像保密,实际操作中一般先将二维图像转换成一维数据,再采用传统加密算法进行加密。与普通的文本信息不同,图像和视频具有时间性、空间性、视觉可感知性,还可进行有损压缩,这些特性使得为图像设计更加高效、安全的加密算法成为可能。

本文重点介绍了基于混沌理论的图像加密算法,对比并研究了几个典型的混沌系统:Logistic映射、Hemon映射、Lorenz系统以及猫映射。最后,在matlab7.8环境下,对灰度图像进行了基于Logistic映射的加密解密,并得出正确的结果。

关键词:Logistic映射;图像加密 ;混沌系统 ;位置置乱

Abstract In the past ten years, with the rapid development of information network technology, the application of multimedia technology in all fields is change rapidly. Digital image has become one of the main object of the internet. Interactive image has been widely used in the important organization of military system, government agencies, medical systems defense systems and financial systems, this also means that the image has many security hidden troubles in the interactive process. If the transmission was malicious third party interception, tamper with, illegal copy, spread, the consequences will be very serious. So the digital image security problems of interaction, has attracted much attention from the public. Therefore, information security has become the focus of people's concern is also the hot spot and difficulty. In order to realize the digital image encryption, the actual operation of the video general first two-dimensional image into one-dimensional data then adopts the traditional encryption. Unlike ordinary text, images and with temporal, spatial, visual perceptibility, also can be loss compression, these features make the image encryption algorithm to design more efficient, safe possible. Image encryption algorithm has gained abundant research achievements, people have designed many image encryption algorithm

This paper introduces image encryption algorithm based on chaotic theory, and studied several typical chaotic systems: Logistic mapping; Lorenz system and cat map. In the matlab7.8 environment, Logistic mapping of the encryption and decryption based on a gray image of arbitrary input, and can get the correct results

Keywords: Logistic map; image encryption; chaotic system; position scrambling

目 录

1 绪论 ....................................................... (1)

1.1 研究背景 ............................................. (1)

1.2 研究方法 ............................................. (1)

1.3 研究内容 ............................................. (2) 2 数字图像加密理论概述 ....................................... (3)

2.1数字图像的基本知识 .................................... (4)

2.2 数字图加密算法的性能要求 ............................. (4)

2.3 数字图像加密算法的分类 ............................... (5)

2.3.1基于矩阵变换像素置换的图像加密技术 .............. (5)【图片加密算法】

2.3.2基于秘密分割与秘密共享的图像加密技术 ............ (6)

2.3.3基于现代密码体制的图像加密技术 .................. (6)

2.3.4基于混沌理论的图像加密算法 ...................... (7) 3 基于混沌理论的图像加密算法 ................................. (8)

3.1 混沌的基本理论 ....................................... (8)

3.1.1 Li-Yorke的混沌定义 ............................. (8)

3.1.2 Devaney 的混沌定义 ............................. (9)

3.1.3 Melnikov 的混沌定义 ............................ (10)

3.2混沌的特征 ........................................... (10)

3.3常见的混沌系统的研究方法 ............................. (11)

3.4几种典型的混沌系统 ................................... (12)

3.5.1

图片加密算法

http://m.zhuodaoren.com/shenghuo345039/

推荐访问:des加密算法 数据加密算法

热点事件推荐文章

推荐内容

上一篇:让乐趣回归生活 下一篇:苏东坡,闲人,张