Total members 11895 |It is currently Sun Dec 22, 2024 7:19 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka






* Project Name:   Advanced Encryption Standard
* Programmer:   msi_333
* Type:   Encryption Algorithms
* Technology:  Java
* IDE:   NetBeans
* Description:   This is a netBeans AES (Cipher and Decipher) project.It include GUI with Text Area for the Key and Orginal Text and Text Area for the Steps

Attachment:
File comment: Structure
AES.gif
AES.gif [ 8.27 KiB | Viewed 20213 times ]

AddRoundKey Package :

Code:
AddRoundKey.java

java code
package AddRoundKey;

import Bitsgetter.bytegetter;

public class AddRoundKey {

/** Creates a new instance of AddRoundKey */
public AddRoundKey() {
}
public String[][] AddRoundKey(String[][] state,String[][] key) {
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
state[i][j]=byteget.xor2hex(state[i][j],key[i][j]);
return state;
}
private bytegetter byteget=new bytegetter((byte)27);



}

Code:
KeyExpansion.java

java code
package AddRoundKey;
import Bitsgetter.bytegetter;
import ase.AES;
import ase.SBox.SBox;
import ase.arrayprinter;

public class KeyExpansion {

/** Creates a new instance of KeyExpansion */
public KeyExpansion() {
}
public void keyExpansion(String[][] mykey){


words[0]=new String[4];
words[1]=new String[4];
words[2]=new String[4];
words[3]=new String[4];
words[0]=mykey[0];
words[1]=mykey[1];
words[2]=mykey[2];
words[3]=mykey[3];


for(int i=4;i<44;i++) {
temp=words[i-1];
System.out.println(temp[0]);
if(i%4==0){
temp= RCxor((SubWord(Rotword(temp))),i/4);


}


words[i]=xor2words(words[i-4],temp);

}

arrayprinter.printarray(words,"key Expantion");
}
public String[] Rotword(String[] word) {
String[] afterRot=new String[4];

for(int i=0;i<3;i++)
afterRot[i]=word[i+1];
afterRot[3]= word[0];
return afterRot;
}
public String[] xor2words(String[] word1,String[] word2) {

newWord=new String[4];


for(int i=0;i<4;i++) {
newWord[i]= byteget.xor2hex( word1[i],word2[i] );

}

return newWord;
}
public String[] SubWord(String[] word) {
String [] aftersub=new String[4];
for(int i=0;i<4;i++) {

aftersub[i]=sbox.getSbox(word[i]);

}
return aftersub;
}
public String[] RCxor(String[] word,int i) {
RCword[0]=RCtable[i-1];

String[] w= xor2words(RCword,word);

return w;
}



public String getKey(){
return k;
}
public String[][] getkeyToRound() {
String[][] roundkey=new String[4][4];
for(int i=0;i<4;i++)
for(int j=0;j<4;j++) {
roundkey[j][i]=words[i+((AES.ROUND-1)*4)][j];
}
return roundkey;
}

public String[][] getWords() {
return words;
}

private SBox sbox=new SBox();
private bytegetter byteget=new bytegetter((byte)27);
String [] temp=new String[4];
String [] RCtable=new String[] {"01","02","04","08","10","20","40","80","1B","36"};
String [] RCword=new String[] {"00","00","00","00",};
String [] word1=new String[4];
String [] word2=new String[4];
String [] word3=new String[4];
String [] word4=new String[4];
String [][] words=new String[44][4];
String [] newWord=new String[4];


String k;

}

Bitsgetter Package :
Code:
bitsgetter.java

java code
package Bitsgetter;

public class bitsgetter {

/** Creates a new instance of bitsgetter */
public bitsgetter() {
}
public byte[] getBinaryBits(int ch) {
byte[] bin=new byte[8];
int tag=1;
for(int i=0;i<8;i++) {
bin[7-i]=(byte)((ch&((tag<<i)))>>i);

}

return bin;
}
public byte[] getBinaryBitsHex(int ch) {

if(ch>=48&ch<=57)
ch-=48;
else ch-=55;

byte[] bin=new byte[8];
int tag=1;
for(int i=0;i<8;i++) {
bin[i]=(byte)((ch&((tag<<i)))>>i);

}

return bin;
}
}

Code:
bytegetter.java

java code
package Bitsgetter;

import Hexdecimal_converter.decimalhex;

public class bytegetter {

/** Creates a new instance of bytegetter */
public bytegetter(byte newcon) {
constant=newcon;
}
public byte Xorbytegetter(String cell,String cell2) {
elements=new byte[4];
elements[0]=(byte)0;
elements[1]=(byte)0;
elements[2]=(byte)0;
elements[3]=(byte)0;
left=bitsgetter.getBinaryBitsHex(cell.charAt(0));
right=bitsgetter.getBinaryBitsHex(cell.charAt(1));

byte cellbyte=(byte)(left[3]*128+left[2]*64+left[1]*32+left[0]*16+right[3]*8+right[2]*4+right[1]*2+right[0]*1);

left2=bitsgetter.getBinaryBitsHex((cell2.charAt(0)));
right2=bitsgetter.getBinaryBitsHex(cell2.charAt(1));

byte cellbyte2=(byte)(left2[3]*128+left2[2]*64+left2[1]*32+left2[0]*16+right2[3]*8+right2[2]*4+right2[1]*2+right2[0]*1);


byte xorbyte;

if(right[0]==1) {

System.out.println("1");
elements[0]=cellbyte2;
}
if(right[1]==1) {
System.out.println("2");
elements[1]=xorByIndex(cellbyte2,1);
}
if(right[2]==1) {
System.out.println("3");
elements[2]=xorByIndex(cellbyte2,2);
}
if(right[3]==1) {
System.out.println("4");
elements[3]=cellbyte2=xorByIndex(cellbyte2,3);
}

System.out.println(right[0]+" "+right[1]+" "+right[2]+" "+right[3]);

return XorAllBytes(elements);

}
public byte do2Xor(byte cell) {

cell=(byte)(cell<<1);
if(left2[3]==1) {

cell=(byte)((cell) ^ constant);

}
return cell;
}
public byte do3Xor(byte cell) {

byte newbyte=cell;


newbyte=do2Xor(cell);


return (byte)(cell ^ newbyte);
}
public byte xorByIndex(byte mydata,int shifts) {
byte returnbyte=mydata;
byte[] bits=new byte[8];

while(shifts>0) {
bits=bitsgetter.getBinaryBits(returnbyte);
returnbyte=(byte)(returnbyte<<1);
if(bits[0]==1) {
returnbyte=(byte)((returnbyte) ^ constant);
}
shifts--;
}
return returnbyte;
}

public byte XorAllBytes(byte[] data) {
byte allxor=(byte)(((data[0]^data[1])^(data[2])^data[3]));
return allxor;
}
public byte justXor(byte cell) {



cell=(byte)((cell) ^ constant);


return cell;
}
public String XorAll(byte[] data) {
byte allxor=(byte)(((data[0]^data[1])^(data[2])^data[3]));

byte[] bits=bitsgetter.getBinaryBits(allxor);
left_value=bits[3]*1+bits[2]*2+bits[1]*4+bits[0]*8;
right_value=bits[7]*1+bits[6]*2+bits[5]*4+bits[4]*8;



return decmhex.getHex(left_value)+decmhex.getHex(right_value);
}
public String xor2hex(String ch1,String ch2) {
left=bitsgetter.getBinaryBitsHex(ch1.charAt(0));
right=bitsgetter.getBinaryBitsHex(ch1.charAt(1));

byte cellbyte=(byte)(left[3]*128+left[2]*64+left[1]*32+left[0]*16+right[3]*8+right[2]*4+right[1]*2+right[0]*1);

left2=bitsgetter.getBinaryBitsHex((ch2.charAt(0)));
right2=bitsgetter.getBinaryBitsHex(ch2.charAt(1));



byte cellbyte2=(byte)(left2[3]*128+left2[2]*64+left2[1]*32+left2[0]*16+right2[3]*8+right2[2]*4+right2[1]*2+right2[0]*1);
byte xor=(byte)(cellbyte^cellbyte2);
byte[] bits=bitsgetter.getBinaryBits(xor);
left_value=bits[3]*1+bits[2]*2+bits[1]*4+bits[0]*8;
right_value=bits[7]*1+bits[6]*2+bits[5]*4+bits[4]*8;
return decmhex.getHex(left_value)+decmhex.getHex(right_value);
}
private bitsgetter bitsgetter=new bitsgetter();
private decimalhex decmhex=new decimalhex();
private byte[] elements;
private byte[] left2;
private byte[] right2;
private byte[] left;
private byte[] right;
private int left_value;
private int right_value;
private byte constant=27;

}


Hexdecimal_converter package :
Code:
decimalhex.java

java code
package Hexdecimal_converter;

public class decimalhex {

/** Creates a new instance of decimalhex */
public decimalhex() {
}
public String getHex(int decimal)
{

if(decimal<10)Hex=Integer.toString(decimal);
else
{
switch(decimal)
{
case 10:Hex="A";break;
case 11:Hex="B";break;
case 12:Hex="C";break;
case 13:Hex="D";break;
case 14:Hex="E";break;
case 15:Hex="F";break;
default:Hex="?";break;
}
}
return Hex;
}
public int getDecimal(char ch)
{


switch(ch)
{
case '0':Decimal=0;break;
case '1':Decimal=1;break;
case '2':Decimal=2;break;
case '3':Decimal=3;break;
case '4':Decimal=4;break;
case '5':Decimal=5;break;
case '6':Decimal=6;break;
case '7':Decimal=7;break;
case '8':Decimal=8;break;
case '9':Decimal=9;break;
case 'A':Decimal=10;break;
case 'B':Decimal=11;break;
case 'C':Decimal=12;break;
case 'D':Decimal=13;break;
case 'E':Decimal=14;break;
case 'F':Decimal=15;break;



default:Decimal=-1;break;
}

return Decimal;
}
String Hex;
int Decimal;
}

Code:
decimalhextable.java

java code
package Hexdecimal_converter;

import Bitsgetter.bitsgetter;

public class decimalhextable {

/** Creates a new instance of decimalhex */
public decimalhextable() {
}
public String[][] getHextable(String data) {
byte[] bitsarray;
for(int i=0;i<16;i++) {

bitsarray=bitsget.getBinaryBits(data.charAt(i));

filltable(i,bitsarray);
}
for(int i=0;i<4;i++) {
System.out.print("|");
for(int j=0;j<4;j++)
System.out.print(Hextable[i][j]+" ");
System.out.println("|");
}
return Hextable;

}

public void filltable(int i,byte[] bits) {

row=i%4;
col=i/4;

left_value=bits[3]*1+bits[2]*2+bits[1]*4+bits[0]*8;
right_value=bits[7]*1+bits[6]*2+bits[5]*4+bits[4]*8;

Hextable[row][col]=decmhex.getHex(left_value)+decmhex.getHex(right_value);
}
public String getString(String[][] myTable) {
byte[] b1,b2;
String str=null;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++) {


b1=bitsget.getBinaryBitsHex(myTable[j][i].charAt(0));
b2=bitsget.getBinaryBitsHex( myTable[j][i].charAt(1));
left_value=b1[3]*128+b1[2]*64+b1[1]*32+b1[0]*16;
left_value+=b2[3]*8+b2[2]*4+b2[1]*2+b2[0]*1;
if(str==null)
{
str=Character.toString((char)left_value);
}
else
str+=Character.toString((char)left_value);

}
return str;
}

private String[][] Hextable=new String[4][4];
private decimalhex decmhex=new decimalhex();
private bitsgetter bitsget=new bitsgetter();

private int col;
private int row;
private int left_value;
private int right_value;

}

Package Mixcolumns :
Code:
invmixcolumns.java

java code
package Mixcolumns;

import Bitsgetter.bytegetter;

public class invmixcolumns {

/** Creates a new instance of invmixcolumns */
public invmixcolumns() {
}
public String[][] invmixcolumns(String[][] state) {
bytegetter=new bytegetter((byte)27);
aftermix=new String[4][4];
data=new byte[4];
for(int i=0;i<4;i++)
for(int j=0;j<4;j++) {
for(int k=0;k<4;k++)
data[k]=bytegetter.Xorbytegetter(trans[i][k],state[k][j]);
aftermix[i][j]=bytegetter.XorAll(data);
}

return aftermix;


}
String[][] trans=new String[][]
{{"0E","0B","0D","09"},
{"09","0E","0B","0D"},
{"0D","09","0E","0B"},
{"0B","0D","09","0E"},
};
String[][] tran2s=new String[][]
{{"02","03","01","01"},
{"01","02","03","01"},
{"01","01","02","03"},
{"03","01","01","02"},
};
private bytegetter bytegetter ;
private String[][] aftermix=new String[4][4];
private byte[] data=new byte[4];
}


Code:
mixcolumns.java

java code
package Mixcolumns;

import Bitsgetter.bytegetter;
import ase.arrayprinter;

public class mixcolumns {

/** Creates a new instance of mixcolumns */
public mixcolumns() {
}
public String[][] mixcolumns(String[][] state) {
bytegetter=new bytegetter((byte)27);
aftermix=new String[4][4];
data=new byte[4];

for(int i=0;i<4;i++)
for(int j=0;j<4;j++) {
for(int k=0;k<4;k++)
{

data[k]=bytegetter.Xorbytegetter(trans[i][k],state[k][j]);
}
aftermix[i][j]=bytegetter.XorAll(data);
}

return aftermix;


}
String[][] trans=new String[][]
{{"02","03","01","01"},
{"01","02","03","01"},
{"01","01","02","03"},
{"03","01","01","02"},
};

private bytegetter bytegetter;
private String[][] aftermix=new String[4][4];
private byte[] data=new byte[4];
}


Package Shiftrow:
Code:
invshiftrows.java

java code
package Shiftrow;

import ase.arrayprinter;

public class invshiftrows {

/** Creates a new instance of invshiftrows */
public invshiftrows() {
}
/** Creates a new instance of shiftrows */

public String[][] invshiftrows(String state[][])
{


for(int i=1;i<4;i++)
{
state=rowshift(i,state);
}
return state;
}
public String[][] rowshift(int row,String[][] state)
{
String temp;
for(int num=0;num<row;num++)
{
temp=state[row][3];
for(int i=3;i>0;i--)
{
state[row][i]=state[row][i-1];
}
state[row][0]=temp;
}
return state;
}
}


Code:
shiftrows.java:

java code
package Shiftrow;

public class shiftrows {

/** Creates a new instance of shiftrows */
public shiftrows() {
}
public String[][] shiftrows(String state[][])
{
for(int i=1;i<4;i++)
{
state=rowshift(i,state);
}
return state;
}
public String[][] rowshift(int row,String[][] state)
{
String temp;
for(int num=0;num<row;num++)
{
temp=state[row][0];
for(int i=0;i<3;i++)
{
state[row][i]=state[row][i+1];
}
state[row][3]=temp;
}
return state;
}


}


package ase:
Code:
ase.java

java code
package ase;

import AddRoundKey.AddRoundKey;
import AddRoundKey.KeyExpansion;
import Hexdecimal_converter.decimalhextable;
import Mixcolumns.invmixcolumns;
import Mixcolumns.mixcolumns;
import Shiftrow.invshiftrows;
import Shiftrow.shiftrows;
import ase.SBox.invSBOX;


import substitution.substitute_bytes;


public class AES {

/** Creates a new instance of ASE_Cipher */
public AES(String key,String PlainText) {
this.plaintext=PlainText;

mykey=key;

fillDataTable();


}
public String ASE_Cipher_loop() {
AESPanel.StepsText.append("***********CIPHER**************"+'\n');
arrayprinter.printarray(state_plain,"Plain Text");
keytable=keyhex.getHextable( mykey);

arrayprinter.printarray(keytable,"Key Hex");
keyexpan.keyExpansion(keytable);


ROUND=1;


AESPanel.StepsText.append("************************"+'\n');
arrayprinter.printarray(keyexpan.getkeyToRound(),"Round key Value");
state_plain=AddRoundkey.AddRoundKey(state_plain,keyexpan.getkeyToRound());

while(ROUND<=9) {
arrayprinter.printarray(state_plain,"Start of Round");
substitute_bytes();
arrayprinter.printarray(state_plain,"After SubBytes");
state_plain=shift.shiftrows(state_plain);
arrayprinter.printarray(state_plain,"After shiftrows");
state_plain=mixer.mixcolumns(state_plain);
arrayprinter.printarray(state_plain,"Mix-columns");
ROUND++;
arrayprinter.printarray(keyexpan.getkeyToRound(),"Round key Value");
state_plain=AddRoundkey.AddRoundKey(state_plain,keyexpan.getkeyToRound());
}
substitute_bytes();

arrayprinter.printarray(state_plain,"After SubBytes");
state_plain=shift.shiftrows(state_plain);
arrayprinter.printarray(state_plain,"After shiftrows");
ROUND++;
state_plain=AddRoundkey.AddRoundKey(state_plain,keyexpan.getkeyToRound());
AESPanel.StepsText.append("**************************"+'\n');
arrayprinter.printarray(state_plain,"Cipher Text");


AESPanel.StepsText.append("****************************"+'\n');
return plainhex.getString(state_plain);
}
public String ASE_Decipher_loop() {
AESPanel.StepsText.append("************************DECIPHER***********************************"+'\n');
ROUND=11;

keytable=keyhex.getHextable(mykey);

keyexpan.keyExpansion(keytable);
arrayprinter.printarray( keyexpan.getWords(),"Key expantintion");


arrayprinter.printarray(state_plain,"Start of Round");
arrayprinter.printarray(keyexpan.getkeyToRound(),"Round key Value");
state_plain=AddRoundkey.AddRoundKey(state_plain,keyexpan.getkeyToRound());
arrayprinter.printarray(state_plain,"After Add round key");
ROUND--;
while(ROUND>1) {


state_plain=invshift.invshiftrows(state_plain);
arrayprinter.printarray(state_plain,"After invshiftrows");

inverssubstitute_bytes();
arrayprinter.printarray(state_plain,"After SubBytes");
arrayprinter.printarray(keyexpan.getkeyToRound(),"Round key Value");
state_plain=AddRoundkey.AddRoundKey(state_plain,keyexpan.getkeyToRound());
arrayprinter.printarray(state_plain,"After Add round key");
state_plain=invmix.invmixcolumns(state_plain);
arrayprinter.printarray(state_plain,"invMix-columns");
ROUND--;

}
state_plain=invshift.invshiftrows(state_plain);
arrayprinter.printarray(state_plain,"After invshiftrows");
inverssubstitute_bytes();
arrayprinter.printarray(state_plain,"After SubBytes");
arrayprinter.printarray(keyexpan.getkeyToRound(),"Round key Value");
state_plain=AddRoundkey.AddRoundKey(state_plain,keyexpan.getkeyToRound());

arrayprinter.printarray(state_plain,"state plain");
AESPanel.StepsText.append("*************************************"+'\n');
arrayprinter.printarray(state_plain,"Plain text");


return plainhex.getString(state_plain);
}
public void fillDataTable() {
state_plain=plainhex.getHextable(plaintext);
}
public void substitute_bytes() {
for(int i=0;i<4;i++) {

for(int j=0;j<4;j++) {
state_plain[i][j]=substit.getsubstitue_bytes(state_plain[i][j]);

}

}

}
public void inverssubstitute_bytes() {
for(int i=0;i<4;i++) {

for(int j=0;j<4;j++) {
state_plain[i][j]=substit.invgetsubstitue_bytes(state_plain[i][j]);

}

}

}


public static int ROUND=1;
private decimalhextable plainhex=new decimalhextable();
private decimalhextable keyhex=new decimalhextable();
private substitute_bytes substit=new substitute_bytes();
private AddRoundKey AddRoundkey=new AddRoundKey();
private KeyExpansion keyexpan=new KeyExpansion();
private mixcolumns mixer=new mixcolumns();
private shiftrows shift=new shiftrows();
private invmixcolumns invmix=new invmixcolumns();
private invshiftrows invshift=new invshiftrows();

private invSBOX invsbox=new invSBOX();
private String plaintext ;

private String mykey;
private String[][] state_plain=new String[4][4];
private String[][] keytable=new String[4][4];



}


Code:
AESMain.java

java code
package ase;
import AddRoundKey.KeyExpansion;
import ase.AES;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;

public class ASEMain {

/** Creates a new instance of DesMain */
public ASEMain() {
}

public static void main(String [] rr){
AESPanel mm = new AESPanel();
mm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mm.setVisible(true);
}
}
class AESPanel extends JFrame{
public static JTextArea StepsText = new JTextArea(17,70);
private AES mm;
private KeyExpansion ee =new KeyExpansion();
private Container c=this.getContentPane();
private JButton btnCihper = new JButton("Cipher");
private JButton btnDeCihper = new JButton("Decipher");

private JTextArea CipherText = new JTextArea(4,70);
private JTextArea OriginalText = new JTextArea(4,70);
private JTextArea DeCipherText = new JTextArea(4,70);


private JScrollPane OriginalScorl=new JScrollPane(OriginalText,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
private JScrollPane CipherScorl=new JScrollPane(CipherText,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
private JScrollPane DecipherScorl=new JScrollPane(DeCipherText,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
private JScrollPane StepScorl=new JScrollPane(StepsText,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
private JTextField KeyWord = new JTextField(16);
private JPanel PanelCipher = new JPanel();
private JPanel PanelDecipher = new JPanel();
private JPanel PanelKeyWord = new JPanel();
private JPanel PanelOriginaltxt = new JPanel();
private JPanel jpstep=new JPanel();
private JLabel lblKeyWord= new JLabel("KeyWord : ");
public AESPanel(){
this.setTitle("AES");
this.setSize(600,700);
this.setVisible(true);
setState(JFrame.MAXIMIZED_BOTH);
setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH);
GenerateGUI();
}


private void GenerateGUI(){

c.setLayout(new FlowLayout());


PanelKeyWord.setLayout(new FlowLayout());
PanelKeyWord.add(lblKeyWord);
PanelKeyWord.add(KeyWord);

PanelOriginaltxt.setBorder(BorderFactory.createTitledBorder("Original Text"));
PanelOriginaltxt.setLayout(new FlowLayout());
PanelOriginaltxt.add(OriginalScorl);

PanelCipher.setBorder(BorderFactory.createTitledBorder("Cipher Text"));
PanelCipher.setLayout(new FlowLayout());
PanelCipher.add(CipherScorl);
PanelCipher.add(btnCihper);

PanelDecipher.setBorder(BorderFactory.createTitledBorder("Decipher Text"));
PanelDecipher.setLayout(new FlowLayout());
PanelDecipher.add(DecipherScorl);
PanelDecipher.add(btnDeCihper);
jpstep.setBorder(BorderFactory.createTitledBorder("Mointor"));
jpstep.setLayout(new FlowLayout());
jpstep.add(StepScorl);


c.add(PanelKeyWord);
c.add(PanelOriginaltxt);
c.add(PanelCipher);
c.add(PanelDecipher);
c.add(jpstep);




DoActions();





}
private void DoActions(){
ActionHandler action = new ActionHandler();

btnCihper.addActionListener(action);
btnDeCihper.addActionListener(action);

}

private class ActionHandler implements ActionListener{


public void actionPerformed(ActionEvent e) {
if(e.getSource()==btnCihper){
String plaintext=OriginalText.getText();
String keyworD=KeyWord.getText();

if(keyworD.length()<16) {
String Massg="Keyword must be 16 character";
JOptionPane.showConfirmDialog(null, Massg,"Error",
JOptionPane.ERROR_MESSAGE);
} else if(plaintext.length()<16) {
String Massg="Original Text must be 16 character or larger";
JOptionPane.showConfirmDialog(null, Massg,"Error",
JOptionPane.ERROR_MESSAGE);
} else {
StepsText.setText(" ");
StepsText.append("keyword : "+keyworD+'\n');
StepsText.append("PlainText : "+plaintext+'\n');
mm= new AES( keyworD,plaintext);



CipherText.append(mm.ASE_Cipher_loop());
}
}
if(e.getSource()==btnDeCihper){
if(mm!=null) {

DeCipherText.setText(mm.ASE_Decipher_loop());
}

}
}

}

}

class DocumentSizeFilter extends DocumentFilter {
int maxCharacters;

public DocumentSizeFilter(int maxChars) {
maxCharacters = maxChars;
}

public void insertString(FilterBypass fb, int offs, String str, AttributeSet a) throws BadLocationException {

if ((fb.getDocument().getLength() + str.length()) <= maxCharacters)
super.insertString(fb, offs, str, a);
else
Toolkit.getDefaultToolkit().beep();
}

public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a) throws BadLocationException {

if ((fb.getDocument().getLength() + str.length()- length) <= maxCharacters)
super.replace(fb, offs, length, str, a);
else
Toolkit.getDefaultToolkit().beep();
}

}

Code:
arrayprinter.java

java code
package ase;

import ase.AESPanel;

public class arrayprinter {


public arrayprinter() {
}
public static void printarray(String[][] arr,String label) {
AESPanel.StepsText.append("-- "+label+" -- "+'\n');

for(int i=0;i<arr.length ;i++) {
AESPanel.StepsText.append("| ");
for(int j=0;j<arr[0].length;j++) {

AESPanel.StepsText.append(arr[i][j]+" ");
}
AESPanel.StepsText.append("| "+'\n');
}
}
}


Package ase.SBox :
Code:
SBox.java

java code
package ase.SBox;

import Hexdecimal_converter.decimalhex;


public class SBox {


public SBox() {
}
public String getSbox(String cell)
{
row=decimalhex.getDecimal(cell.charAt(0));
col=decimalhex.getDecimal(cell.charAt(1));
return sbox[row][col];
}
private String sbox[][]=new String[][]
{{"63" , "7C" , "77" , "7B" , "F2" , "6B" , "6F" , "C5" , "30" , "01" , "67" , "2B" , "FE" , "D7" , "AB" , "76"},
{"CA" , "82" , "C9" , "7D" , "FA" , "59" , "47" , "F0" , "AD", "D4", "A2" , "AF" , "9C" , "A4" , "72" , "C0"},
{"B7" , "FD", "93" , "26" , "36" , "3F" , "F7" , "CC" , "34" , "A5" , "E5" , "F1" , "71" , "D8" , "31" , "15"},
{"04" , "C7", "23" , "C3", "18", "96" , "05" , "9A" , "07" , "12" , "80" , "E2" , "EB" , "27" , "B2" , "75"},
{"09" , "83", "2C", "1A", "1B" , "6E" , "5A" , "A0" , "52" , "3B" , "D6" , "B3" , "29" , "E3" , "2F" , "84" },
{"53" , "D1", "00", "ED", "20" , "FC" , "B1" , "5B" , "6A" , "CB" , "BE" , "39" , "4A" , "4C" , "58" , "CF" },
{"D0" , "EF" , "AA" , "FB", "43", "4D", "33" , "85", "45", "F9" , "02" , "7F" , "50" , "3C", "9F" , "A8"},
{"51" , "A3" , "40" , "8F" , "92" , "9D" , "38" , "F5" , "BC" , "B6" , "DA" ,"21" , "10" , "FF" , "F3" , "D2"},
{"CD" , "0C" , "13" , "EC" , "5F" , "97" , "44" , "17" , "C4" , "A7" , "7E" , "3D" , "64" , "5D" , "19" , "73"},
{"60" , "81" , "4F" , "DC" , "22" , "2A" , "90" , "88" , "46" , "EE" , "B8" , "14" , "DE", "5E" , "0B" , "DB"},
{"E0" , "32", "3A" , "0A", "49", "06" , "24" , "5C" , "C2" , "D3" , "AC" , "62", "91" , "95" , "E4", "79"},
{"E7" , "C8" , "37" , "6D", "8D" , "D5" , "4E" , "A9" , "6C", "56" , "F4" , "EA" , "65", "7A" , "AE" , "08"},
{"BA" , "78" , "25", "2E", "1C", "A6", "B4" , "C6", "E8" , "DD" ,"74" , "1F" , "4B" , "BD", "8B", "8A"},
{"70" , "3E", "B5" , "66", "48", "03" , "F6" , "0E", "61", "35" , "57" , "B9", "86" , "C1", "1D" , "9E"},
{"E1", "F8", "98", "11", "69", "D9" ,"8E" ,"94", "9B", "1E", "87", "E9", "CE" , "55", "28" ,"DF"},
{"8C" , "A1" , "89" , "0D" , "BF" , "E6" , "42" , "68" , "41" , "99" , "2D" , "0F" , "B0" , "54" , "BB", "16"}};
private decimalhex decimalhex=new decimalhex();
private int row;
private int col;
}

Code:
invSBox.java

java code
package ase.SBox;

import Hexdecimal_converter.decimalhex;

public class invSBOX {

/** Creates a new instance of invSBOX */
public invSBOX() {
}
public String getinvSbox(String cell) {
row=decimalhex.getDecimal(cell.charAt(0));
col=decimalhex.getDecimal(cell.charAt(1));
return invsbox[row][col];
}
private String invsbox[][]=new String[][]{
{ "52", "09", "6A", "D5", "30", "36", "A5", "38", "BF", "40" ,"A3", "9E", "81", "F3", "D7", "FB" },
{"7C", "E3", "39", "82", "9B", "2F", "FF", "87", "34", "8E", "43", "44", "C4", "DE", "E9", "CB" },
{"54" ,"7B", "94", "32", "A6", "C2", "23", "3D", "EE", "4C", "95", "0B", "42", "FA", "C3", "4E" },
{"08", "2E", "A1", "66" ,"28", "D9", "24", "B2", "76", "5B", "A2", "49", "6D", "8B", "D1", "25" },
{"72", "F8", "F6", "64" ,"86", "68", "98", "16", "D4", "A4", "5C", "CC", "5D", "65", "B6", "92" },
{ "6C", "70", "48", "50", "FD", "ED", "B9", "DA", "5E", "15", "46", "57", "A7", "8D", "9D", "84" },
{ "90", "D8","AB", "00", "8C", "BC", "D3", "0A", "F7", "E4", "58", "05", "B8", "B3", "45", "06", },
{"D0", "2C", "1E", "8F", "CA", "3F", "0F", "02", "C1", "AF", "BD", "03", "01", "13", "8A", "6B"} ,
{"3A", "91", "11", "41", "4F", "67", "DC", "EA", "97", "F2", "CF", "CE", "F0", "B4", "E6", "73", },
{ "96", "AC", "74", "22", "E7", "AD", "35", "85", "E2", "F9", "37", "E8", "1C", "75", "DF", "6E", },
{"47", "F1", "1A", "71", "1D", "29", "C5", "89", "6F", "B7", "62", "0E", "AA", "18", "BE", "1B"} ,
{"FC", "56", "3E", "4B", "C6", "D2", "79", "20", "9A", "DB", "C0", "FE", "78", "CD", "5A", "F4",},
{"1F", "DD", "A8", "33", "88", "07", "C7", "31", "B1", "12", "10","59", "27", "80", "EC", "5F"} ,
{"60", "51", "7F", "A9", "19", "B5", "4A", "0D", "2D", "E5", "7A", "9F", "93", "C9", "9C", "EF"},
{"A0", "E0", "3B", "4D", "AE", "2A", "F5", "B0", "C8", "EB", "BB", "3C", "83", "53", "99", "61" },
{"17", "2B", "04", "7E", "BA", "77", "D6", "26", "E1", "69", "14", "63", "55", "21", "0C", "7D"}};
private decimalhex decimalhex=new decimalhex();
private int row;
private int col;


}


substitution package
Code:
substitute_bytes.java :

java code
package substitution;

import ase.SBox.SBox;
import ase.SBox.invSBOX;

public class substitute_bytes {

/** Creates a new instance of substitute_bytes */
public substitute_bytes()
{
}
public String getsubstitue_bytes(String cell)
{
return sbox.getSbox(cell);
}
public String invgetsubstitue_bytes(String cell)
{
return invsbox.getinvSbox(cell);
}

private SBox sbox=new SBox();
private invSBOX invsbox=new invSBOX();
private int row;
private int col;

}

Attachment:
File comment: AES Screenshot
aes.GIF
aes.GIF [ 21.69 KiB | Viewed 24940 times ]





Attachments:
File comment: AES project source code
ASE.rar [57.65 KiB]
Downloaded 4462 times

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

thanks, i want to buil email ecryption with AES. can you hel me ???

[email protected]

because i am student at eepis-its.edu and my project is encrypt email with AES

please help me !!!

may be you have example code AES GUI/APPLET in java neatbeans , implementation to email

thnks :this:



Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

what you mean by "Email encryption "


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

hiiiii....
how i can use this algorithm with voice i mean in real-time is there any voice chat using AES algorithm by any lang



Author:
Newbie
User avatar Posts: 3
Have thanks: 0 time

thanks



Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

can any one help me please............
I need a project of encryption of text and image files using AES algorithm in C++............
plzz.............its really urgent............mail it on [email protected]



Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

thanks for this code. can anyone help me for the IDEA encryption algorithm like this DES and AES?
please reply as soon as possible.



Author:

Cipher and Decipher examples :
java/advanced-encryption-standard-aes-example-cipher-step1-t182.html
java/advanced-encryption-standard-aes-example-decipher-step2-t183.html


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 8 posts ] 

  Related Posts  to : Advanced Encryption Standard (AES)
 Advanced Encryption Standard (AES)-Example-Cipher (Step1)     -  
 Advanced Encryption Standard (AES)-Example-Decipher (Step2)     -  
 Advanced Encryption Standard (AES)-Java Project     -  
 Encryption Algorithm{Data Encryption Standard}     -  
 Data Encryption Standard (DES)     -  
 DES J# Data Encryption Standard     -  
 Data Encryption Standard(DES) using C Language     -  
 AES (Advanced Encryption standards) Java Applet     -  
 Encryption and Decryption encryption Affine cipher code     -  
 Standard Huffman Coding     -  



Topic Tags

Java Projects, Java Algorithms







Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com