You are on page 1of 5

Isu Dan Prinsip Proteksi Teknologi Informasi

Transposisi Kolom

Oleh:

Dewa Gede Yudiana (1504505017)

TEKNOLOGI INFORMASI
FAKULTAS TEKNIK
UNIVERSITAS UDAYANA
2017
Aplikasi Enkripsi Transposisi Kolom Pada Java

1. Transposisi Kolom

import java.util.ArrayList;

public class Transposisi {

public ArrayList<String> keyWords = new ArrayList<String>();


public char[][] plainText;
public char[] chipperText;

public void transKolom(String msgInput)


{ int[] intKW = new
int[keyWords.size()]; int temp;

if(msgInput.length()%keyWords.size() != 0){
plainText = new
char[msgInput.length()/keyWords.size()+1][keyWords.size()];
} else {
plainText = new
char[msgInput.length()/keyWords.size()][keyWords.size()];
}

chipperText = new char[plainText.length*plainText[0].length];

for(int indexPTX = 0; indexPTX < plainText.length; indexPTX++){


for(int indexPTY = 0; indexPTY < plainText[0].length;
indexPTY++){
if((indexPTX*plainText[0].length+indexPTY) <
msgInput.length()){
plainText[indexPTX][indexPTY] =
msgInput.toUpperCase().charAt(indexPTX*plainText[0].length+indexPTY);
} else{
plainText[indexPTX][indexPTY] = (char) (90 -
(plainText[0].length - indexPTY - 1));
}
}
}

for(int indexKW = 0; indexKW < keyWords.size(); indexKW++){

intKW[indexKW] = keyWords.get(indexKW).charAt(0);
}

for(int indexINTKW = 0; indexINTKW < intKW.length - 1; indexINTKW++){


int pos = 1;
for(int indexINTKW2 = indexINTKW + 1; indexINTKW2 < intKW.length;
indexINTKW2++){
if(intKW[indexINTKW] > intKW[indexINTKW2]){
pos = indexINTKW2;
temp = intKW[indexINTKW];
intKW[indexINTKW] = intKW[pos];
intKW[pos] = temp;
} else{
pos = indexINTKW;
}
}
}

for(int indexPTY = 0; indexPTY < plainText[0].length; indexPTY++){


char kW = (char) intKW[indexPTY];
int indexCTY = keyWords.indexOf(Character.toString(kW));
for(int indexPTX = 0; indexPTX < plainText.length; indexPTX++){
chipperText[indexPTX*plainText[0].length + indexPTY] =
plainText[indexPTX][indexCTY];
System.out.print(chipperText[indexPTX*plainText[0].length +
indexPTY]);

}
keyWords.set(indexCTY, null);
}
}

public Transposisi(String keyWordsInput) {

for(int indexKW = 0; indexKW < keyWordsInput.length(); indexKW++){

keyWords.add(Character.toString(keyWordsInput.charAt(indexKW)).toUpperCase())
;
}

2. Main
import java.util.Scanner;

public class Main {

static Scanner input = new Scanner(System.in);

public static void main(String[] args)

{ System.out.println("Input Kata

Kuncinya"); System.out.print("kata kunci

:");

String key = input.next().toString();


System.out.println("Input Pesan");

System.out.print("Pesan :");

String msg = input.next().toString();

System.out.println("Hasil enkripsi:");

System.out.print("\nSubtitusi diagonal: ");

Subtitusi mySub = new Subtitusi(key);

mySub.outByDiagonals(msg);

System.out.print("\nTransposisi kolom: ");

Transposisi myTra = new Transposisi(key);

myTra.transKolom(msg);

static void test(){

String key = input.next().toString();

String msg = input.next().toString();

Subtitusi mySub = new Subtitusi(key);

Transposisi myTra = new Transposisi(key);

myTra.transKolom(msg);

System.out.print("\n");

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

for(int k = 0; k < myTra.plainText[0].length; k++){

System.out.print(myTra.plainText[j][k]+" ");

}
System.out.print("\n");

3. Hasil Run Project