Lorem ipsum dolor sit amet, consectetur adipiscing elit. Test link
Postingan

RC4 Encryption

Berikut ini adalah source code sederhana untuk enkripsi RC4. Source code ini dibuat menggunakan bahasa pemrograman Java.


import java.io.*;

//import java.lang.Character;

/**

*

* @author zlich

*/

public class RC4 {

public static void main (String [] args) throws IOException {

int [] key = null;

int keylen = 0;

int k = 0;

int [] SBox = new int [256]; DataInputStream input = new DataInputStream(System.in);
//inisialisasi S-Box

for (int i = 0; i 0) {

key = new int [keylen];

}

for (k=0; k<keylen; k++) {

key[k] = kunci.charAt(k);
System.out.print(key[k] + " ");

}
//permutasi S-Box

int i, j = 0;

for (i=0; i<256; i++) {

j = (j + SBox[i] + key[i % key.length]) % 256;
//swap

int temp = SBox[i];

SBox[i] = SBox[j];

SBox[j] = temp;

}
//Input Plaintext

System.out.println("\nPlaintext: ");

String plaintext = input.readLine();
//PRGA

int a = 0;

int b = 0;

for (i=0; i<plaintext.length(); i++) {

a = (a + 1) % 256;

b = (b + SBox[a]) % 256;
//swap

int temp = SBox[a];

SBox[a] = SBox[b];

SBox[b] = temp;
//pseudorandom generation

int pseudo = SBox[(SBox[a] + SBox[b]) % 256];

int chartext = plaintext.charAt(i);
//XOR

int chiper = pseudo ^ chartext;

System.out.print(Integer.toHexString(chiper).toUpperCase()); //chipertext

//System.out.print(Character.toChars(chiper));

}

}

}




Source codenya masih menggunakan prosedural, untuk pendekatan OOP sedang diusahakan.
Kalau dicompile terus dieksekusi outputnya kayak gini:

Key:
pwd12
112 119 100 49 50
Plaintext:
Math 310 Proves!
6CA86FE3CBC33C162595C3E78B9C97BC
Selamat Mencoba!!
Lay out and vector designer, 'little' programmer.

3 komentar

  1. i have a question. This statement:

    for (int i = 0; i 0)

    is this right? coz i have error for this
  2. Oh sorry, that a mistake. that code shold be:

    for (i=0; i<plaintext.length(); i++)

    I have already fixed it.
    thanks.
  3. g bisa bro max
    input key nya gimana?
    variabel kuncinya itu gimana?