导航:首页 > 源码编译 > idea算法

idea算法

发布时间:2022-02-04 18:04:57

1. idea加密算法属于什么密码体制

在对称密钥体制中,它的加密密钥与解密密钥的密码体制是相同的,且收发双方必须共享密钥,对称密码的密钥是保密的,没有密钥,解密就不可行,知道算法和若干密文不足以确定密钥。公钥密码体制中,它使用不同的加密密钥和解密密钥,且加密密钥是向公众公开的,而解密密钥是需要保密的,发送方拥有加密或者解密密钥,而接收方拥有另一个密钥。两个密钥之一也是保密的,无解密密钥,解密不可行,知道算法和其中一个密钥以及若干密文不能确定另一个密钥。
优点:对称密码技术的优点在于效率高,算法简单,系统开销小,适合加密大量数据。对称密钥算法具有加密处理简单,加解密速度快,密钥较短,发展历史悠久等优点。
缺点:对称密码技术进行安全通信前需要以安全方式进行密钥交换,且它的规模复杂。公钥密钥算法具有加解密速度慢的特点,密钥尺寸大,发展历史较短等特点。

2. 简述des、idea、aes算法不用

对称加密(也叫私钥加密)指加密和解密使用相同密钥的加密算法。有时又叫传统密码算法,就是加密密钥能够从解密密钥中推算出来,同时解密密钥也可以从加密密钥中推算出来。

而在大多数的对称算法中,加密密钥和解密密钥是相同的,所以也称这种加密算法为秘密密钥算法或单密钥算法。它要求发送方和接收方在安全通信之前,商定一个密钥。

对称算法的安全性依赖于密钥,泄漏密钥就意味着任何人都可以对他们发送或接收的消息解密,所以密钥的保密性对通信性至关重要。

3. 安全密钥异同性分,AES和IDEA属于什么算法

aes和idea都是对称加密算法,他们都是块加密的算法,idea是在des的基础上发展起来的,aes是对des的替代算法。他的密钥比idea要长,所以安全性也好一些。

4. idea算法问题

因为idea使用的三种计算操作是异域,65536和65537分别叫做模65536加法和模65537乘法。65537是一个质数,以它为模保证了取模乘法的可逆性。

5. java环境下实现idea算法的加密解密

基于Java的IDEA加密算法探讨
随着Internet的迅速发展,电子商务的浪潮势不可挡,日常工作和数据传输都放在Internet网上进行传输,大大提高了效率,降低了成本,创造了良好的效益。但是,由于 Internet网络协议本身存在着重要的安全问题(IP包本身并不继承任何安全特性,很容易伪造出IP包的地址、修改其内容、重播以前的包以及在传输途中拦截并查看包的内容),使网上的信息传输存在巨大的安全风险电子商务的安全问题也越来越突出。加密是电子商务中最主要的安全技术,加密方法的选取直接影响电子商务活动中信息的安全程度,在电子商务系统中,主要的安全问题都可以通过加密来解决。数据的保密性可通过不同的加密算法对数据加密来实现。
对我国来讲,虽然可以引进很多的外国设备,但加密设备不能依靠引进,因为它涉及到网络安全、国家机密信息的安全,所以必须自己研制。当前国际上有许多加密算法,其中DES(Data Encryption Standard)是发明最早的用得最广泛的分组对称加密算法,DES用56位蜜钥加密64位明文,输出64位密文,DES的56位密钥共有256 种可能的密钥,但历史上曾利用穷举攻击破解过DES密钥,1998年电子边境基金会(EFF)用25万美元制造的专用计算机,用56小时破解了DES的密钥,1999年,EFF用22小时完成了破解工作,使DES算法受到了严重打击,使它的安全性受到严重威胁。因为JAVA语言的安全性和网络处理能力较强,本文主要介绍使用IDEA(Internation Data Encryption Algorithm )数据加密算法在Java环境下实现数据的安全传输。

一、IDEA数据加密算法

IDEA数据加密算法是由中国学者来学嘉博士和着名的密码专家 James L. Massey 于1990年联合提出的。它的明文和密文都是64比特,但密钥长为128比特。IDEA 是作为迭代的分组密码实现的,使用 128 位的密钥和 8 个循环。这比 DES 提供了更多的 安全性,但是在选择用于 IDEA 的密钥时,应该排除那些称为“弱密钥”的密钥。DES 只有四个弱密钥和 12 个次弱密钥,而 IDEA 中的弱密钥数相当可观,有 2 的 51 次方个。但是,如果密钥的总数非常大,达到 2 的 128 次方个,那么仍有 2 的 77 次方个密钥可供选择。IDEA 被认为是极为安全的。使用 128 位的密钥,蛮力攻击中需要进行的测试次数与 DES 相比会明显增大,甚至允许对弱密钥测试。而且,它本身也显示了它尤其能抵抗专业形式的分析性攻击。

二、Java密码体系和Java密码扩展

Java是Sun公司开发的一种面向对象的编程语言,并且由于它的平台无关性被大量应用于Internet的开发。Java密码体系(JCA)和Java密码扩展(JCE)的设计目的是为Java提供与实现无关的加密函数API。它们都用factory方法来创建类的例程,然后把实际的加密函数委托给提供者指定的底层引擎,引擎中为类提供了服务提供者接口在Java中实现数据的加密/解密,是使用其内置的JCE(Java加密扩展)来实现的。Java开发工具集1.1为实现包括数字签名和信息摘要在内的加密功能,推出了一种基于供应商的新型灵活应用编程接口。Java密码体系结构支持供应商的互操作,同时支持硬件和软件实现。Java密码学结构设计遵循两个原则:(1)算法的独立性和可靠性。(2)实现的独立性和相互作用性。算法的独立性是通过定义密码服务类来获得。用户只需了解密码算法的概念,而不用去关心如何实现这些概念。实现的独立性和相互作用性通过密码服务提供器来实现。密码服务提供器是实现一个或多个密码服务的一个或多个程序包。软件开发商根据一定接口,将各种算法实现后,打包成一个提供器,用户可以安装不同的提供器。安装和配置提供器,可将包含提供器的ZIP和JAR文件放在CLASSPATH下,再编辑Java安全属性文件来设置定义一个提供器。Java运行环境Sun版本时,提供一个缺省的提供器Sun。

三、Java环境下的实现

1.加密过程的实现

void idea_enc( int data11[], /*待加密的64位数据首地址*/ int key1[]){

int i ;

int tmp,x;

int zz[]=new int[6];

for ( i = 0 ; i < 48 ; i += 6) { /*进行8轮循环*/

for(int j=0,box=i; j<6; j++,box++){

zz[j]=key1[box];

}

x = handle_data(data11,zz);

tmp = data11[1]; /*交换中间两个*/

data11[1] = data11[2];

data11[2] = tmp;

}

tmp = data11[1]; /*最后一轮不交换*/

data11[1] = data11[2];

data11[2] = tmp;

data11[0] = MUL(data11[0],key1[48]);

data11[1] =(char)((data11[1] + key1[49])%0x10000);

data11[2] =(char)((data11[2] + key1[50])%0x10000);

data11[3] = MUL(data11[3],key1[51]);

}

2.解密过程的实现

void key_decryExp(int outkey[])/*解密密钥的变逆处理*/

{ int tmpkey[] = new int[52] ;

int i;

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

tmpkey[i] = outkey[ wz_spkey[i] ] ; /*换位*/

}

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

outkey[i] = tmpkey[i];

}

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

outkey[wz_spaddrever[i]] = (char)(65536-outkey[wz_spaddrever[i]]) ; /*替换成加法逆*/

}

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

outkey[wz_spmulrevr[i]] =(char)(mulInv(outkey[wz_spmulrevr[i]] )); /*替换成乘法逆*/

}

}

四、总结

在实际应用中,我们可以使用Java开发工具包(JDK)中内置的对Socket通信的支持,通过JCE中的Java流和链表,加密基于Socket的网络通信.我们知道,加密/解密是数据传输中保证数据完整性的常用方法,Java语言因其平台无关性,在Internet上的应用非常之广泛.使用Java实现基于IDEA的数据加密传输可以在不同的平台上实现并具有实现简洁、安全性强等优点。

6. 哪位大哥能给我一个基于IDEA算法的c或者c++的软件以及源代码啊

c++ code
////////////////////////////////////////////////////////
//
// Project: Implementation of IDEA (International
// Data Encryption Algorithm)
//
// ECE 575 Term Project
// Winter 2003
// Author: Irwin Yoon
//
// Overview: This code does the following:
// - print out all encryption and
// decryption subkeys which are used
// in the encryption and decryption
// process
// - encrypts plaintext message
// - decrypts ciphertext message
// - shows detailed, round by round results
// (8 total)
// Program contains a user driven menu where the user can select
// initial 128-bit key and also select messages to decrypt
// and encrypt.
//
// Compiling: This has been verified to work on SunOS
// with g++ compiler (flop.engr.orst.e).
// To Compile: g++ Idea.cpp -o Idea.exe
//
// Note: This code is a little sloppy. Coding could
// be made more efficient.
//
// Usage: Run executable with no arguments: Idea.exe
// Then select appropriate menu options
//
//
//
//////////////////////////////////////////////

// main() is at the bottom of file!

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <cassert>
#include <string>

//globals
#define NUMSUBKEYS 52
#define NUMROUNDS 8
#define MAXINPUTSIZE 32

// I had problems if we use #define with
// these nums. Problem arose when taking
// mod of this number
unsigned int TWOPOWER16 = 65536;
unsigned int TWOPOWER161 = 65537;
unsigned int inputsize;

// all the subkey information
unsigned short esubkeys[NUMSUBKEYS];
unsigned short dsubkeys[NUMSUBKEYS];
unsigned int origkeyint[4];
unsigned char origkeychar[17];

//****************************************
// argument is an array of chars and prints
// the hex value of 4 consecutive chars (4 bytes)
// starting at the pointer. It loops until
// all the bits in the original string are read
//****************************************

void printHex (unsigned char* start)
{
unsigned int* val = (unsigned int*)start;
int times = inputsize/4;
cout <<endl;
for (int i=0; i<times;i++) {
printf ("\t\tbits %03d to %03d: 0x%08x\n",(32*i)+1,8*4*(i+1),*val);
start+=4;
val = (unsigned int*)start;
}
}

//****************************************
// This is the core encryption and decryption
// engine which does all the rounds and does
// all the arithmetic operations (add,mult,xor,swap,inverse)
//****************************************

void runIdea(unsigned char* msg, unsigned char* outmsg,unsigned short* keysbit16,int writeflag)
{

//if writeflag is 1, then we print round by round results

unsigned short x1,x2,x3,x4;
unsigned short y1,y2,y3,y4;
unsigned short x5,x6,x7,x8,x9,x10;
unsigned short x11,x12,x13,x14;
unsigned short xtemp;
unsigned int writeint;

// msg is 1 byte. make 2 byte ptr to facilitate ing for
// 16 bit fields
// 2 bytes go into x1, 2 bytes go into x2,etc
unsigned short* msgbit16 = (unsigned short*) msg;
//cout << "msg is " << *msg <<endl;
x1 = *msgbit16++;
x2 = *msgbit16++;
x3 = *msgbit16++;
x4 = *msgbit16++;

//x1 = (x1 >>8) | (x1<<8);
//x2 = (x2 >>8) | (x2<<8);
//x3 = (x3 >>8) | (x3<<8);
//x4 = (x4 >>8) | (x4<<8);

// this is for debug purposes. make greater than 8
// if don't want debugs
int tst=9;

// note that mod 2^16+1 could yield a value which is 2^16.
// this is greater than space for 16 bits, so i think
// the mod operation makes 2^16 mod 2^16+1 equal to 0.

for (int i=0; i<NUMROUNDS;i++)
{
//IY

if (i==tst )
cout << "STEP 1: x1 is " << x1 << ", key is " << *keysbit16 << endl;
//STEP 1 of 14
x1 = (x1* (*keysbit16++)) % TWOPOWER161;
//IY
if (i==tst )
cout << "\tAfter mul, x1 is " << x1 << endl;

//IY
if (i==tst )
cout << "STEP 2: x2 is " << x2 << ", key is " << *keysbit16 << endl;

//STEP 2 of 14
x2 = (x2 + *keysbit16++) % TWOPOWER16;

//IY
if (i==tst )
cout << "\tAfter add, x2 is " << x2 << endl;

//IY
if (i==tst )
cout << "STEP 3: x3 is " << x3 << ", key is " << *keysbit16 << endl;
//STEP 3 of 14
x3 = (x3 + *keysbit16++) % TWOPOWER16;

//IY
if (i==tst )
cout << "\tAfter add, x3 is " << x3 << endl;

//IY
if (i==tst )
cout << "STEP 4: x4 is " << x4 << ", key is " << *keysbit16 << endl;

//STEP 4 of 14
x4 = (x4* (*keysbit16++)) % TWOPOWER161;
//IY
if (i==tst )
cout << "\tAfter mul, x4 is " << x4 << endl;

//IY
if (i==tst)
cout << "STEP 5: x3 is " << x3 << ", x1 is " << x1 << endl;

//STEP 5 of 14
x5 = x1^x3;
if (i==tst)
cout << "\tAfter XOR, x5 is " << x5 << endl;

//IY
if (i==tst)
cout << "STEP 6(outorder): x2 is " << x2 << ", x4 is " << x4 << endl;

//STEP 6 of 14
x6 = x2^x4;

//IY
if (i==tst)
cout << "\tAfter XOR, x6 is " << x6 << endl;

//IY
if (i==tst)
cout << "STEP 7(outorder): x5 is " << x5 << ", key is " << *keysbit16 << endl;

//STEP 7 of 14
x7 = (x5* (*keysbit16++)) % TWOPOWER161;

if (i==tst)
cout << "\tAfter mul, x7 is " << x7 << endl;

//IY
if (i==tst)
cout << "STEP 8: x6 is " << x6 << ", x7 is " << x7 << endl;

//STEP 8 of 14
x8 = (x6+x7) % TWOPOWER16;

//IY
if (i==tst)
cout << "\tAfter ADD, x8 is " << x8 << endl;

//IY
if (i==tst)
cout << "STEP 9: x8 is " << x8 << ", key is " << *keysbit16 << endl;

//STEP 9 of 14
x9 = (x8* (*keysbit16++)) % TWOPOWER161;

//IY
if (i==tst)
cout << "\tAfter mul, x9 is " << x9 << endl;

//IY
if (i==tst)
cout << "STEP 10: x7 is " << x7 << ", x9 is " << x9 << endl;

//STEP 10 of 14
x10 = (x7+x9) % TWOPOWER16;
//IY
if (i==tst)
cout << "\tAfter add, x10 is " << x10 << endl;

//STEP 11,12,13,14 of 14
x11=x1^x9;
x12=x3^x9;
x13=x2^x10;
x14=x4^x10;

if (i==tst ) {
cout << "\tSTEP11: After XOR, x11 is " << x11 << endl;
cout << "\tSTEP12: After XOR, x12(after swap) is " << x12 << endl;
cout << "\tStep13: After XOR, x13(after swap) is " << x13 << endl;
cout << "\tStep14: After XOR, x14 is " << x14 << endl;
}

//new values for next iteration
x1=x11;
x2=x12;
x3=x13;
x4=x14;

if (writeflag==1) {
printf ("ROUND %d:\n", i+1);
writeint = (x1<<16) + x2;
printf("\tBits 1 to 32 0x%08x\n",writeint);
writeint = (x3<<16) + x4;
printf("\tBits 33 to 64 0x%08x\n\n",writeint);
}
} // foreach round

//final output transformation. modify 4 subkeys like so:
y1 = (x11 * (*keysbit16++)) % TWOPOWER161;
//flip flop these two!
y3 = (x13 + *keysbit16++) % TWOPOWER16;
y2 = (x12 + *keysbit16++) %TWOPOWER16;
y4 = (x14 * (*keysbit16)) % TWOPOWER161;

// put new data into the buffer
msgbit16=(unsigned short*)outmsg;

*msgbit16++ = y1;
*msgbit16++ = y3;
*msgbit16++ = y2;
*msgbit16 = y4;

//*msgbit16++ = (y1 >>8) | (y1<<8);
//*msgbit16++ = (y3 >>8) | (y3<<8);
//*msgbit16++ = (y2 >>8) | (y2<<8);
//*msgbit16 = (y4 >>8) | (y4<<8);

if (writeflag==1) {
unsigned int tempint;
printf ("AFTER OUTPUT TRANSFORMATION AND SWAP:\n");
msgbit16=(unsigned short*)outmsg;
tempint = (y1 <<16) + y3;
printf ("\tBits 1 to 32 0x%08x\n",tempint);
tempint = (y2 <<16) + y4;
printf ("\tBits 33 to 64 0x%08x\n",tempint);
}
} // end runIdea

//****************************************
// each block is 8 bytes (64 bits), so
// we loop until all blocks have been encrypted
// essentially hands over work to runIdea
//****************************************

void encrypt (unsigned char* msg,unsigned char* outmsg,int writeflag)
{
int blocks = inputsize/8;
unsigned char* inptr=msg;
unsigned char* outptr=outmsg;
for(int i=0;i<blocks;i++) {
if (writeflag==1) {
printf ("Results for Data Block %d\n", i+1);
printf ("=======================\n\n");
}
runIdea(inptr,outptr,esubkeys,writeflag);
inptr+=8;
outptr+=8;
}
}

//****************************************
// each block is 8 bytes (64 bits), so
// we loop until all blocks have been decrypted
// essentially hands over work to runIdea
//****************************************
void decrypt (unsigned char* msg,unsigned char* outmsg,int writeflag)
{
int blocks = inputsize/8;
unsigned char* inptr=msg;
unsigned char* outptr=outmsg;
for(int i=0;i<blocks;i++) {
if (writeflag==1) {
printf ("Results for Data Block %d\n", i+1);
printf ("=======================\n\n");
}
runIdea(inptr,outptr,dsubkeys,writeflag);
inptr+=8;
outptr+=8;
}
} //end of decrypt

//****************************************
// Finds the inverse of a 16 bit number mod 2^16+1
// uses extended euclidean algorithm
//****************************************

//unsigned short inv(unsigned short b)
short inv(unsigned short b)
{

// what book said to do if taking mod of 0 or 1
if (b==0 || b==1)
return b;

// initial variables
int a = 65536+1; // 2^16 + 1
int g0 = a;
int g1 = b;
int v0 = 0;
int v1 = 1;
int savev0;
int q;
int rem;
int numloops = 0;

// start of extended euglidean algorithm
while (g1 != 0) {
numloops++;
q = g0/g1;
rem = g0 % g1;
g0=g1;
g1 = rem;
savev0=v0;
v0 = v1;
v1 = savev0 - (v1*q);
}
assert (g0==1);

//IMPORTANT - since we're dealing wih signs, if we end up with a negative
// number, for some reason the positive equivalent was off by 1. so add
// 1 to value if negative result was found. Not sure why.
if (v0 >1)
return v0;
else
return 1+v0;
} // end inv

//****************************************
// Prints the original 128 bit key in hex
//****************************************
void printOrigKey()
{
printf ("Original Key in text: %s\n",origkeychar);
printf ("\tOriginal Key 1st 32bits: 0x%08x\n",origkeyint[0]);
printf ("\tOriginal Key 2nd 32bits: 0x%08x\n",origkeyint[1]);
printf ("\tOriginal Key 3rd 32bits: 0x%08x\n",origkeyint[2]);
printf ("\tOriginal Key 4th 32bits: 0x%08x\n",origkeyint[3]);
}

//****************************************
// Prints out the 52 subkeys used for encryption
// and decryption
//****************************************
void printKeys()
{

int count=1;
cout << "\n\n***** ENCRYPTION AND DECRYPTION SUBKEY SUMMARY *****" <<endl;
cout << endl << "All Subkeys are 16 bits." <<endl<<endl;

printOrigKey();

for (int k=0; k<NUMSUBKEYS;k++) {
if (k%6 ==0) {
cout <<"\nEncryption Subkeys Round " << count ;
cout <<" Decryption Subkeys Round " << count << endl;
count++;
}
printf (" subkey %02d 0x%08x",k,esubkeys[k]);
printf (" subkey %02d 0x%08x\n",k,dsubkeys[k]);

}

}//end printKeys

//****************************************
// based on the 52 encryption subkeys, find
// tje 52 decryption subkeys (16 bit)
//****************************************
void calcDKeys ()
{

//*** 1st,4th subkey for each round
for (int i=0;i<NUMSUBKEYS;i+=6) {
dsubkeys[i] = inv(esubkeys[48-i]);
dsubkeys[i+3] = inv(esubkeys[48-i+3]);
}

//*** 2nd, 3rd subkey for each round
dsubkeys[1] = -1 * esubkeys[49]; //first round
dsubkeys[2] = -1 * esubkeys[50]; //first round

for (int i =7; i<NUMSUBKEYS;i+=6) {
dsubkeys[i] = -1 * esubkeys[51-i];
dsubkeys[i+1] = -1 * esubkeys[50-i];
}
dsubkeys[49] = -1 * esubkeys[1]; //last round
dsubkeys[50] = -1 * esubkeys[2]; //last round

//*** 5th, 6th subkey for each round
for (int i=4; i< (NUMSUBKEYS) ; i+=6) {
dsubkeys[i] = esubkeys[50-i];
dsubkeys[i+1] = esubkeys[51-i];
}

int count=1;
for (int k=0; k<NUMSUBKEYS;k++) {
if (k%6 ==0) {
//IY cout <<"\nDSUBKEYS FOR ROUND " << count << endl;
count++;
}
//IY cout <<"subkey " << k << " = " << dsubkeys[k]<<endl;
}
} //end calcDKeys

//****************************************
// Takes original 128 bit key which is
// passed in as array of bytes and
// calculate encryption subkeys (52 total - 16 bits)
//****************************************
void calcEKeys(unsigned char* userkey)
{

//keys from example
//char userkey[16];

//for(int i=0; i<16; i++)
//userkey[i] = i+1;

int firstbyte = 0;

//merge two 8-bit sections into one 16 bit!!!
// this is done by bitwise shifting. most of logic in this
// funciton is because of this

for (int j=0; j<8;j++) {
esubkeys[j] = (userkey[firstbyte] <<8) + userkey[firstbyte+1];
firstbyte = firstbyte+2;
}

for (int f=8; f<NUMSUBKEYS-4;f+=8) {
//shift 25 bits.
//if we're on subkey 1, then get last 7 bits of subkey 2, and
//first 9 bits of subkey 2

// first 6 subkeys
for (int n=0;n<6;n++) {
esubkeys[f+n] = (short) ((esubkeys[f+n-7] <<9) | (esubkeys[f+n-6] >>7));
}

// next 2 esubkeys
esubkeys[f+6] = (short) ((esubkeys[f+6-7] <<9) | (esubkeys[f+6-6-8]>>7));
esubkeys[f+7] = (short) ((esubkeys[f+7-7-8] <<9) | (esubkeys[f+7-6-8]>>7));
}

// subkeys 48-51
esubkeys[NUMSUBKEYS-4] = (short) ((esubkeys[NUMSUBKEYS-4-7] <<9) | (esubkeys[NUMSUBKEYS-4-6] >>7));
esubkeys[NUMSUBKEYS-4+1] = (short) ((esubkeys[NUMSUBKEYS-4+1-7] <<9) | (esubkeys[NUMSUBKEYS-4+1-6] >>7));
esubkeys[NUMSUBKEYS-4+2] = (short) ((esubkeys[NUMSUBKEYS-4+2-7] <<9) | (esubkeys[NUMSUBKEYS-4+2-6] >>7));
esubkeys[NUMSUBKEYS-4+3] = (short) ((esubkeys[NUMSUBKEYS-4+3-7] <<9) | (esubkeys[NUMSUBKEYS-4+3-6] >>7));

int count=1;
for (int k=0; k<NUMSUBKEYS;k++) {
if (k%6 ==0) {
//cout <<"\nSUBKEYS FOR ROUND " << count << endl;
count++;
}
//cout <<"subkey " << k<< " = " << esubkeys[k]<<endl;
}
} //end calcEKeys

//****************************************
// states that program has started.
//****************************************
void promptWelcome()
{
if (sizeof(unsigned short)!=2){
cout <<" size of unsigned short is not 2 bytes. Please run on flop.engr.orst.e or on another machine. This program needs 2 bytes for unsigned short to simulate the 16-bit subkeys" <<endl;
exit(0);
}

cout << endl <<endl;
cout << "************ WELCOME ***************" <<endl;
cout << "This is Irwin Yoon's program illustrating " <<endl;
cout << "IDEA (International Data Encryption Algorithm)" <<endl;
cout << "************************************" <<endl;
cout << endl <<endl;
} //end promptWelcome

//****************************************
// prompt the user to enter either plaintext
// or ciphertext. puts value in array
// that is passed in
//****************************************
void promptForText(unsigned char* ptext,int encryptionflag)
{

std::string str;
if (encryptionflag ==1)
cout << endl << "************ ENCRYPTION OF PLAINTEXT **********" <<endl<<endl;
else
cout << endl << "************ DECRYPTION OF CIPHERTEXT **********" <<endl<<endl;
while (1) {
cout << "Data block size is 8 bits. " <<endl;
cout << "Therefore, please enter 8, 16, 24, 32 characters" <<endl;
if (encryptionflag ==1)
cout << "Your Plaintext input: ";
else
cout << "Your Ciphertext input: ";

getline(cin, str);

if ((str.size() == 8) || (str.size()==16) || (str.size()==24) || (str.size()==32))
break;
else
cout <<endl<< "ERROR: input was " << str.size()<< " instead of 8,16,24,32 chars. Try Again" <<endl <<endl;
}
inputsize = str.size();

for (int i=0;i<str.size();i++) {
ptext[i] = str[i];
}
ptext[inputsize]='\0';
} //prompt for plaintext

//****************************************
// We have to prompt user to enter 128 bit
// key. since we only have 1 byte chars
// make the user enter 16 characters, which
// we convert to 128 bit key
//****************************************
void promptForKey()
{
cout << "IDEA takes in a 128-bit key. " <<endl;
cout << "User will enter 16 alphanumeric characters" <<endl;
cout << "These 16 alphanumeric characters will be "<< endl;
cout << "converted to a 128-bit key. " <<endl;
cout << " (16 char * 8bits = 128 bits)" <<endl;

cout << endl <<endl;

std::string str;
while (1) {
cout << "Please enter 16 alphanumberic characters, then press enter" <<endl;
getline(cin, str);

if (str.size() == 16)
break;
else
cout <<endl<< "ERROR: That was not 16 alphanumeric chars. Try Again" <<endl <<endl;
}

for (int i=0;i<16;i++) {
origkeychar[i] = str[i];

}
origkeychar[16]='\0';
cout << endl << "Thank you."<<endl ;

//translate to hex
int firstbyte = 0;
for (int j=0; j<4;j++) {
//merge two 8-bit sections into one 16 bit
origkeyint[j] = (origkeychar[firstbyte] <<24) + (origkeychar[firstbyte+1]<<16)
+ (origkeychar[firstbyte+2]<<8) + (origkeychar[firstbyte+3]);
firstbyte = firstbyte+4;
}
printOrigKey();
} //end promptForKey

//****************************************
// prints hex and ascii of plaintext
//****************************************
void printPlainTextSummary(unsigned char* plaintext)
{
plaintext[inputsize]='\0';
printf ("\n\nYour Plaintext\n");
printf ("=================================\n");
printf ("Plaintext in ASCII: \"%s\"\n",plaintext);
printf ("Plaintext in Hex:");
printHex(plaintext);
}

//****************************************
// prints hex of ciphertext
//****************************************
void printCipherTextSummary(unsigned char* ciphertext)
{
ciphertext[inputsize] = '\0';
printf ("\n\nThe Resulting Ciphertext\n");
printf ("=================================\n");
printf ("Ciphertext in Hex:");
printHex(ciphertext);
}

//****************************************
// prints hex and ascii of decrypted
// ciphertext
//****************************************
void printDecipherTextSummary(unsigned char* decipheredtext)
{
decipheredtext[inputsize] = '\0';
printf ("\n\nDecrypt the Ciphertext\n");
printf ("=================================\n");
printf ("Decrypted text in ASCII: \"%s\"\n",decipheredtext);
printf ("Decrypted text in Hex:");
printHex(decipheredtext);
}

//****************************************
// THE MAIN LOOP! CONTINUALLY prompts
// user for input and processes request
//****************************************

int main()
{

promptWelcome();
promptForKey();

//NOTE: override user prompted key only for testing purposes
//unsigned char origkeychar[17];
//for(int i=0; i<16; i++)
//origkeychar[i] = i+1;
//origkeychar[16]='\0';

calcEKeys(origkeychar);
calcDKeys();

std::string str;
unsigned char ciphertext[MAXINPUTSIZE+1];
unsigned char decipheredtext[MAXINPUTSIZE+1];
unsigned char plaintext[MAXINPUTSIZE+1];
ciphertext[MAXINPUTSIZE] = '\0';
decipheredtext[MAXINPUTSIZE] = '\0';
unsigned int myint;
unsigned int* intptr;

//*********************
//******** MAIN LOOP
//*********************

while (1) {
cout << endl <<endl << "MAIN MENU" <<endl;
cout << "=========" <<endl;
cout << "Press 1 to print all Encryption/decryption keys " <<endl;
cout << "Press 2 to encrypt plaintext with intermediate results" <<endl;
cout << "Press 3 to decipher ciphertext with intermediate results" <<endl;
cout << "Press 4 to encrypt, then decrypt "
<< "(No intermediate results shown)" <<endl;
cout << "Press 5 to quit " <<endl<<endl;
cout << "Your choice: " ;
getline(cin, str);

// I should probably use switch statements instead, but it's
// too late
if (str[0] == '1')
printKeys();
else if (str[0]=='2') {
promptForText(plaintext,1);
encrypt(plaintext,ciphertext,1);
printCipherTextSummary(ciphertext);
}
else if (str[0]=='3') {
promptForText(ciphertext,0);
decrypt(ciphertext,decipheredtext,1);
printDecipherTextSummary(decipheredtext);
}
else if(str[0]=='4') {
promptForText(plaintext,1);
encrypt(plaintext,ciphertext,0);
decrypt(ciphertext,decipheredtext,0);
printPlainTextSummary(plaintext);
printCipherTextSummary(ciphertext);
printDecipherTextSummary(decipheredtext);

}
else if(str[0]=='5') {
cout << "****** Exiting IDEA program. Good bye. " <<endl<<endl;
exit(0);
}
else {
cout <<"Error: Invalid input" <<endl;
}

} // end main loop

return 0;
} //end main

7. IDEA算法中,add和multiple操作为什么mod的数差1

——我不信命,我信爱情是没有理由悲欢的注定。

8. 高分求C# idea算法

利用File.Encrypt()方法对某个文件进行加密

9. 现在哪种加密算法安全AES,IDEA,RC系,Tirple DES,CAST5,Blowfish

AES-256和RSA-2048绝对可以,用RSA加密密匙,AES加密数据,因为非对称算法加密数据速度实在太慢,所以用非对称算法加密数据根本行不通,但是安全性非常高。

10. idea的IT

加密算法
是旅居瑞士中国青年学者来学嘉和着名密码专家J.Massey于1990年提出的。它在1990年正式公布并在以后得到增强。这种算法是在DES算法的基础上发展出来的,类似于三重DES,和DES一样IDEA也是属于对称密钥算法。发展IDEA也是因为感到DES具有密钥太短等缺点,已经过时。IDEA的密钥为128位,这么长的密钥在今后若干年内应该是安全的。
类似于DES,IDEA算法也是一种数据块加密算法,它设计了一系列加密轮次,每轮加密都使用从完整的加密密钥中生成的一个子密钥。与DES的不同处在于,它采用软件实现和采用硬件实现同样快速。
由于IDEA是在美国之外提出并发展起来的,避开了美国法律上对加密技术的诸多限制,因此,有关IDEA算法和实现技术的书籍都可以自由出版和交流,可极大地促进IDEA的发展和完善。
IDEA曾今也是AES算法标准的主要竞争者,其安全性已经在国际密码年会上被证明。
在PGP(pretty good privacy)中,IDEA算法被采用。
64-位数据分组被分成4个16-位子分组:xl,X2,x3,x4。这4个子分组成为算法的第一轮的输入,总共有8轮。在每一轮中,这4个子分组相列相异或,相加,相乘,且与6个16-位子密钥相异或,相加,相乘。在轮与轮间,第二和第:个子分组交换。最后在输出变换中4个子分组与4个子密钥进行运算。
在每一轮中,执行的顺序如下:(以下表述中的相加指的是两个数mod 2^256 相加,例如:(a + b) mod p,其结果是a+b算术和除以p的余数,也就是说,(a+b) = kp +r,则 (a+b) mod p =r,又例如对于下列表述中的“(2)X2和第二个子密钥相加”就是指用X2与第二个子密钥的和除以2^16(即65536)后的余数。对于以下表述中的相乘,指的是:(a × b) mod p,其结果是 a × b算术乘法除以p的余数,又例如对于下列表述中的“(1)X1和第一个子密钥相乘。”就是指用X1和第一个子密钥相乘后的积除于(2^16+1)(即65537)后的余数。异或指的是不进位加法。)
(1)X1和第一个子密钥相乘。
(2)X2和第二个子密钥相加。
(3)X3和第三个子密钥相加。
(4)X4和第四个子密钥相乘。
(5)将第(1)步和第(3)步的结果相异或。·
(6)将第(2)步和第(4)步的结果相异或。
(7)将第(5)步的结果与第五个子密钥相乘。
(8)将第(6)步和第(7)步的结果相加。
(9)将第(8)步的结果与第六个子密钥相乘。
(10)将第(7)步和第(9)步的结果相加。
(11)将第(1)步和第(9)步的结果相异或。
(12)将第(3)步和第(9)步的结果相异或。
(13)将第(2)步和第(10)步的结果相异或。
(14)将第(4)步和第(10)步的结果相异或。
每一轮的输出是第(11)、(12)、(13)和(14) 步的结果形成的4个子分组。将中间两个分组分组交换(最后一轮除外)后,即为下一轮的输入。
经过8轮运算之后,有一个最终的输出变换:
(1) X1和第一个子密钥相乘。
(2) X2和第二个子密钥相加。
(3) X3和第三个子密钥相加。
(4) X4和第四个子密钥相乘。
最后,这4个子分组重新连接到一起产生密文。
产生子密钥也很容易。这个算法用了52个子密钥(8轮中的每一轮需要6个,其他4个用与输出变换)。首先,将128-位密钥分成8个16-位子密钥。这些是算法的第一批8个子密钥(第一轮六个,第二轮的头两个)。然后,密钥向左环移25位后再分成8个子密钥。开始4个用在第二轮,后面4个用在第三轮。密钥再次向左环移25位产生另外8个子密钥,如此进行D算法结束。
解密过程基本上一样,只是子密钥需要求逆且有些微小差别,解密子密钥要么是加密子密钥的加法逆要么是乘法逆。(对IDEA而言,对于模256十1乘,全0子分组用256=-l来表示,因此0的乘法逆是0)。计算子密钥要花点时间,但对每一个解密密钥,只需做一次。
关于IDEA中运用的很多概念,需要参考数论中的知识,如有疑问,可以参考以下资料:计算机密码学(卢开澄着清华大学出版社出版),计算机密码学及其应用,初等数论,数论导引(华罗庚着)等。关于IDEA运用的数学原理,均可在以上资料中获得答案。
IDEA奖项
国际杰出设计奖(Instrial Design Excellence Awards)

阅读全文

与idea算法相关的资料

热点内容
c编程用英文还是中文 浏览:723
一点都不解压的游戏 浏览:203
解压为什么不能用中文文件夹 浏览:615
服务器如何解除备份 浏览:144
安卓手机为什么用一年就变卡 浏览:11
如何用风变编程自动回复 浏览:512
安卓阅读币怎么样 浏览:437
京东app怎么切号 浏览:583
进入传奇服务器后如何修改 浏览:42
m0单片机的cycle怎么知道 浏览:806
linux命令太长 浏览:782
压缩机nb1111y是多少w 浏览:45
打赏视频用什么服务器好 浏览:154
方舟好友服务器怎么加mod 浏览:982
javaresponse设置编码 浏览:842
opc数据采集源码 浏览:563
命令女孩子 浏览:691
rtsp录像源码 浏览:388
加密狗复制啥意思 浏览:545
键盘文件夹重命名输入不了 浏览:413