Transposition Cipher

Hi All,

I've just made my own program which is Encrypting the plaintexts using Transposition Techniques, but I dont know how to decrypt it! here is my code code

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

publicclass Transposisi{

publicstaticvoid main (String[]args){

new MenuGUI();

}

}

class MenuGUIextends JFrameimplements ActionListener{

JTextArea io =new JTextArea();

JButton btnEncry =new JButton("Encrypts");

JButton btnExit =new JButton("Exit");

JButton btnDecry =new JButton("Decrypt");

//JButton btnClear = new JButton("Clear");

MenuGUI(){

super("Teknik Subsitusi : Transposisi");

getContentPane().setLayout(new BorderLayout());

setSize(350,300);

setLocation(200,250);

io.setLineWrap(true);

io.setWrapStyleWord(true);

JScrollPane jsp =new JScrollPane(io);

btnEncry.addActionListener(this);

btnEncry.setActionCommand("Encry");

btnExit.addActionListener(this);

btnExit.setActionCommand("Exit");

btnDecry.addActionListener(this);

btnDecry.setActionCommand("Decrypt");

/*btnClear.addActionListener(this);

btnDecry.setActionCommand("Clear");*/

JPanel pnlBawah =new JPanel();

pnlBawah.setLayout(new FlowLayout());

pnlBawah.add(btnEncry);

pnlBawah.add(btnDecry);

//pnlBawah.add(btnClear);

pnlBawah.add(btnExit);

getContentPane().add(jsp,BorderLayout.CENTER);

getContentPane().add(pnlBawah, BorderLayout.SOUTH);

setVisible(true);

}

publicvoid actionPerformed(ActionEvent e){

if(e.getActionCommand().equalsIgnoreCase("Encry")==true){

String plainTeks = io.getText();

String cipherTeks="";

double panjang = plainTeks.length();

int ukuran_matrik = (int)Math.ceil(Math.sqrt(panjang));

char[][]data =newchar[ukuran_matrik+1][ukuran_matrik+1];

int k = 0;

selesai:

for(int i = 1;i<data.length;i++){

for(int j = 1;j<data[i].length;j++){

if(k>=(int)panjang){

break selesai;

}

data[i][j]=plainTeks.charAt(k);

k=k+1;

}

}

String kunci = JOptionPane.showInputDialog(this,"Key("+ ukuran_matrik +")","Transposition",JOptionPane.QUESTION_MESSAGE);

for(int j = 0;j<kunci.length();j++){

int kunci_pisah = Integer.parseInt(kunci.substring(j,j+1));

for (int i = 1; i><data.length;i++)

{

if((int)data[i][kunci_pisah]==0){

continue;

}

cipherTeks +=data[i][kunci_pisah];

}

}

io.setText(cipherTeks);

}

else{

this.dispose();

System.exit(0);

}

}

}

thanx anyway!>

[5629 byte] By [husnia] at [2007-10-2 20:35:49]
# 1

> I've just made my own program which is Encrypting the plaintexts using Transposition Techniques,

> but I dont know how to decrypt it!

In that case it may be worth providing the code which does the actual encryption, but we don't need the GUI code.

Is the transposition permutation a deterministic function of the message length and the key? If not, you need to rethink it.

Is it possible from the cipher text to know the length of the plaintext? If not, you need to rethink it.

If you answered "Yes" to both those questions, then you can take the ciphertext and key and reconstruct the function mapping plaintext index to ciphertext index. Then for each plaintext index [0..n-1] you can find the corresponding ciphertext index, and from that the corresponding character.

YAT_Archivista at 2007-7-13 23:19:02 > top of Java-index,Java Essentials,Java Programming...
# 2
i still dont understand!! in this case i use a key that depends on the length of the plaintext and then it scrambled with that key using transposition method, would you mind to solve my problem....
husnia at 2007-7-13 23:19:02 > top of Java-index,Java Essentials,Java Programming...