source code for implementation of idea algorithm in java
#1

Assalamu'alaikum,, what is the source code algorithm IDE for Encryption and decryption in java? Help me pleas, thank you
Reply
#2
source code for implementation of idea algorithm in java

001
import java.util.*;
002
import java.io.*;
003
import java.math.BigInteger;
004
class decrypt
005
{
006
static String circular_shift(String s)
007
{
008

009
String y="";
010

011
for(int i=25;i<128;i++)
012
y+=s.charAt(i);
013

014
for(int i=0;i<25;i++)
015
y=y+s.charAt(i);
016

017
return y;
018

019
}
020
static String xor(String x,String y)
021
{
022
String z="";
023
if(x.length()<16)
024
for(int i=x.length();i<16;i++)
025
x="0"+x;
026
if(y.length()<16)
027
for(int i=y.length();i<16;i++)
028
y="0"+y;
029
for(int i=15;i>=0;i--)
030
{
031
if(x.charAt(i)==y.charAt(i))
032
z="0"+z;
033
else
034
z="1"+z;
035
}
036
return z;
037
}
038
static String mod_add(String x,String y)
039
{
040
int temp1=Integer.parseInt(x,2);
041
int temp2=Integer.parseInt(y,2);
042
long l=(long) (temp1+temp2);
043
long ans=(long)(l%(Math.pow(2,16)));
044
String ans1=Long.toBinaryString(ans);
045
return ans1;
046
}
047
static String mod_mul(String x,String y)
048
{
049
int temp1=Integer.parseInt(x,2);
050
int temp2=Integer.parseInt(y,2);
051
long l=(long)temp1*temp2;
052
long ans=(long)(l%(Math.pow(2,16)+1));
053
String ans1=Long.toBinaryString(ans);
054

055
return ans1;
056
}
057
static String add_inv(String x)
058
{
059
long n1=Long.parseLong(x,2);
060
long k=(long)Math.pow(2,16);
061
if(n1>k)
062
n1=n1%k;
063
n1=k-n1;
064

065
String ans=Long.toBinaryString(n1);
066
if(ans.length()<16)
067
for(int i=ans.length();i<16;i++)
068
ans="0"+ans;
069
return ans;
070

071
}
072
static String mul_inv(String x)
073
{
074
BigInteger n1=new BigInteger(x,2);
075
long k=(long)Math.pow(2,16);
076
k=k+1;
077
String m=k+"";
078
BigInteger m1=new BigInteger(m);
079
n1=n1.modInverse(m1);
080
String ans=n1.toString(2);
081
if(ans.length()<16)
082
for(int i=ans.length();i<16;i++)
083
ans="0"+ans;
084
return ans;
085
}
086

087

088
public static void main(String args[])
089
{
090
String key="";
091
for(int i=0;i<128;i++)
092
{
093
int x=(Math.random()<0.5)?0:1;
094
key+=x;
095
}
096
System.out.println("key "+key);
097
BigInteger bigInt1 = new BigInteger(key, 2);
098
String hex=bigInt1.toString(16);
099
System.out.println("key hex "+ hex);
100

101

102

103

104
String subk[]=new String[52];
105
int x,y;
106
for(int j=0;j<6;j++)
107
{
108
x=0;
109
for(int i=0;i<8;i++)
110
{
111
subk[i+(8*j)]=key.substring(x,x+16);
112
x=x+16;
113
}
114
key=circular_shift(key);
115
}
116
subk[48]=key.substring(0,16);
117
subk[49]=key.substring(16,32);
118
subk[50]=key.substring(32,48);
119
subk[51]=key.substring(48,64);
120

121
// for(int i=0;i<52;i++)
122
// System.out.println("subkey "+i+"\t"+subk[i]);
123
String input="01101000011001010110110001101100011011110111011101101111011100100110110001100100";
124
BigInteger bigInt = new BigInteger(input, 2);
125
String hex1=bigInt.toString(16);
126
System.out.println("input hex "+ hex1);
127

128

129

130
String i[]=new String[4];
131
i[0]=input.substring(0,16);
132

133
i[1]=input.substring(16,32);
134

135
i[2]=input.substring(32,48);
136

137
i[3]=input.substring(48,64);
138

139
String d[]=new String[15];
140

141
for(int j=0;j<8;j++)
142
{
143

144
d[1]=mod_mul(i[0],subk[0+(6*j)]);
145

146
d[2]=mod_add(i[1],subk[1+(6*j)]);
147

148
d[3]=mod_add(i[2],subk[2+(6*j)]);
149

150
d[4]=mod_mul(i[3],subk[3+(6*j)]);
151

152
d[5]=xor(d[1],d[3]);
153
d[6]=xor(d[2],d[4]);
154
d[7]=mod_mul(d[5],subk[4+(6*j)]);
155

156
d[8]=mod_add(d[6],d[7]);
157
d[9]=mod_mul(d[8],subk[5+(6*j)]);
158

159
d[10]=mod_add(d[7],d[9]);
160
d[11]=xor(d[1],d[9]);
161
d[12]=xor(d[3],d[9]);
162
d[13]=xor(d[2],d[10]);
163
d[14]=xor(d[4],d[10]);
164

165
i[0]=d[11];
166
i[1]=d[13];
167
i[2]=d[12];
168
i[3]=d[14];
169
}
170
d[1]=mod_mul(i[0],subk[48]);
171
String ohex1=Long.toHexString(Long.parseLong(d[1],2));
172
d[2]=mod_add(i[1],subk[49]);
173
String ohex2=Long.toHexString(Long.parseLong(d[2],2));
174
d[3]=mod_add(i[2],subk[50]);
175
String ohex3=Long.toHexString(Long.parseLong(d[3],2));
176
d[4]=mod_mul(i[3],subk[51]);
177
String ohex4=Long.toHexString(Long.parseLong(d[4],2));
178

179
i[0]=d[1];
180
i[1]=d[2];
181
i[2]=d[3];
182
i[3]=d[4];
183
String cipher=ohex1+ohex2+ohex3+ohex4;
184

185
System.out.println("cipher "+cipher);
186

187

188
int outp1,outp2;
189
String p1;
190
String p2;
191
for(int j=1;j<5;j++)
192
{
193
if(d[j].length()<16)
194
for(int k=d[j].length();k<16;k++)
195
d[j]="0"+d[j];
196

197
System.out.println("d "+d[j]);
198
p1=d[j].substring(0,8);
199
p2=d[j].substring(8,16);
200
outp1=Integer.parseInt(p1,2);
201
outp2=Integer.parseInt(p2,2);
202
System.out.println("outp1 "+outp1 +(char)outp1);
203
System.out.println("outp2 "+outp2 +(char)outp2);
204
}
205
//decryption subkeys
206
String invk[]=new String[52];
207
invk[0]=mul_inv(subk[48]);
208
invk[1]=add_inv(subk[49]);
209
invk[2]=add_inv(subk[50]);
210
invk[3]=mul_inv(subk[51]);
211
invk[4]=(subk[46]);
212
invk[5]=(subk[47]);
213

214

215
invk[6]=mul_inv(subk[42]);
216
invk[7]=add_inv(subk[44]);
217
invk[8]=add_inv(subk[43]);
218
invk[9]=mul_inv(subk[45]);
219
invk[10]=(subk[40]);
220
invk[11]=(subk[41]);
221

222
invk[12]=mul_inv(subk[36]);
223
invk[13]=add_inv(subk[38]);
224
invk[14]=add_inv(subk[37]);
225
invk[15]=mul_inv(subk[39]);
226
invk[16]=(subk[34]);
227
invk[17]=(subk[35]);
228

229
invk[18]=mul_inv(subk[30]);
230
invk[19]=add_inv(subk[32]);
231
invk[20]=add_inv(subk[31]);
232
invk[21]=mul_inv(subk[33]);
233
invk[22]=(subk[28]);
234
invk[23]=(subk[29]);
235

236
invk[24]=mul_inv(subk[24]);
237
invk[25]=add_inv(subk[26]);
238
invk[26]=add_inv(subk[25]);
239
invk[27]=mul_inv(subk[27]);
240
invk[28]=(subk[22]);
241
invk[29]=(subk[23]);
242

243
invk[30]=mul_inv(subk[18]);
244
invk[31]=add_inv(subk[20]);
245
invk[32]=add_inv(subk[19]);
246
invk[33]=mul_inv(subk[21]);
247
invk[34]=(subk[16]);
248
invk[35]=(subk[17]);
249

250
invk[36]=mul_inv(subk[12]);
251
invk[37]=add_inv(subk[14]);
252
invk[38]=add_inv(subk[13]);
253
invk[39]=mul_inv(subk[15]);
254
invk[40]=(subk[10]);
255
invk[41]=(subk[11]);
256

257
invk[42]=mul_inv(subk[6]);
258
invk[43]=add_inv(subk[8]);
259
invk[44]=add_inv(subk[7]);
260
invk[45]=mul_inv(subk[9]);
261
invk[46]=(subk[4]);
262
invk[47]=(subk[5]);
263

264
invk[48]=mul_inv(subk[0]);
265
invk[49]=add_inv(subk[1]);
266
invk[50]=add_inv(subk[2]);
267
invk[51]=mul_inv(subk[3]);
268

269
/* for(int l1=0;l1<52;l1++)
270
{
271
BigInteger ibigInt = new BigInteger(invk[l1], 2);
272
String ihex=ibigInt.toString(16);
273
System.out.println("inverse hex "+l1+" "+ ihex);
274

275
}*/
276

277
for(int j=0;j<8;j++)
278
{
279

280
d[1]=mod_mul(i[0],invk[0+(6*j)]);
281
d[2]=mod_add(i[1],invk[1+(6*j)]);
282
d[3]=mod_add(i[2],invk[2+(6*j)]);
283
d[4]=mod_mul(i[3],invk[3+(6*j)]);
284
d[5]=xor(d[1],d[3]);
285
d[6]=xor(d[2],d[4]);
286
d[7]=mod_mul(d[5],invk[4+(6*j)]);
287
d[8]=mod_add(d[6],d[7]);
288
d[9]=mod_mul(d[8],invk[5+(6*j)]);
289
d[10]=mod_add(d[7],d[9]);
290
d[11]=xor(d[1],d[9]);
291
d[12]=xor(d[3],d[9]);
292
d[13]=xor(d[2],d[10]);
293
d[14]=xor(d[4],d[10]);
294
i[0]=d[11];
295
i[1]=d[13];
296
i[2]=d[12];
297
i[3]=d[14];
298
}
299
d[1]=mod_mul(i[0],invk[48]);
300
String dhex1=Long.toHexString(Long.parseLong(d[1],2));
301
d[2]=mod_add(i[1],invk[9]);
302
String dhex2=Long.toHexString(Long.parseLong(d[2],2));
303
d[3]=mod_add(i[2],invk[50]);
304
String dhex3=Long.toHexString(Long.parseLong(d[3],2));
305
d[4]=mod_mul(i[3],invk[51]);
306
String dhex4=Long.toHexString(Long.parseLong(d[4],2));
307

308

309
String decrypt=dhex1+dhex2+dhex3+dhex4;
310

311
System.out.println("decrypt "+decrypt);
312

313
}
314
}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: isu string, java based ieee reseach idea, idea algorithm code java, source code for implementation of the fp growth algorithm, java code for idea algorithm implementation, implementation of lamport algorithm in java code, omr source code in java to implementation,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  free download source code of online college magazine 5 17,573 29-06-2018, 10:09 AM
Last Post: Guest
  opengl source code for butterfly 3 3,241 14-05-2018, 08:57 AM
Last Post: Akshatha k
  ice cream parlour management system in vb source code 4 5,256 04-04-2018, 11:58 PM
Last Post: vprk77
  dwt code in java for image 2 6,335 24-03-2018, 10:06 PM
Last Post: Guest
  source code in php for online training and placement cell management 1 6,665 23-03-2018, 09:06 AM
Last Post: ritzi
  free download college website project in html with source code 2 4,601 24-02-2018, 10:46 AM
Last Post: Guest
  ppt on design and implementation of intelligent campus security tracking system based on rfid and zigbee 7 15,900 09-02-2018, 02:20 PM
Last Post: udaya
  source code for hospital management system in jsp 4 1,937 13-01-2018, 10:51 AM
Last Post: dhanabhagya
  source code in c for dna cryptography in computer sc ppt 1 1,514 09-01-2018, 09:59 PM
Last Post: harshavarshinib
  to find whether a number is krishnamurthy number or not using java 1 11,244 01-01-2018, 11:39 AM
Last Post: dhanabhagya

Forum Jump: