導航:首頁 > 源碼編譯 > 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演算法相關的資料

熱點內容
android圖片變灰 瀏覽:268
linuxvi下一個 瀏覽:973
安卓手機的應用鎖怎麼解 瀏覽:735
linux增加路徑 瀏覽:849
sql身份證號最後四位加密 瀏覽:533
xp系統表格加密 瀏覽:856
光遇安卓軍大衣什麼時候上線 瀏覽:840
android應用商店圖標 瀏覽:341
java計算圓的面積 瀏覽:643
應用編譯優化recovery 瀏覽:577
域控命令n 瀏覽:258
php導出文件 瀏覽:13
谷歌地圖網頁版無法連接伺服器地址 瀏覽:298
菜鳥工具在線編譯python 瀏覽:858
柵格化命令有何作用 瀏覽:825
為什麼壓縮文件不能解壓 瀏覽:311
足球app哪個軟體好 瀏覽:96
產品經理逼瘋程序員的一天 瀏覽:17
修改svn伺服器ip地址 瀏覽:584
下列關於編譯說法正確的是 瀏覽:246