Here is one example of the science of cryptographic algorithms called Qwerty (originaled by: Dwindy Stanza & Paiman). As the name implies, QWERTY, this algorithm adapted to the standard keyboard board. The principle works something like this:
A : index 0 = Q : index 0
B : index 1 = W : index 1
C : index 2 = E : index 2
D : index 3 = R : index 3
...
Z : index 25 = M : index 25
That's for the first letter, while for the second letter there is a shift in the index, so that A is no longer the Q, but the W. And Q was changed to the last index that W to M shifted one index. And so on.
A : index 0 = W : index 0
B : index 1 = E : index 1
C : index 2 = R : index 2
D : index 3 = T : index 3
...
Z : index 25 = Q : index 25
Prior to implementation of the program code, first create the components needed, ie
1. JPanel txtPlain
2. JPanel txtChiper
3. JButton btnEncrypt
4. JButton btnDecrypt
Encrypt used to translate the text into chiper Plain text, while Decrypt chiper translate text into plain text.
For implementation in java, something like this for action btnEncrypt:
private void btnEncryptActionPerformed(java.awt.event.ActionEvent evt) {
char [] kode = {'Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M' };
char [] abc = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
int ketemu=0;
char tampung = 0;
String plaintext = txtPlain.getText();
char[] ciphertext = new char[plaintext.length()];
if (!plaintext.equals(""))
txtPlain.setText(plaintext);
for(int w = 0; w
tampung = plaintext.toUpperCase().charAt(w) ;
for(int x = 0 ; x<=25 ; x++){
if(tampung == abc[x] ){
ketemu = x;
}
// else{ ketemu = -1; }
ciphertext[w] = kode[ketemu];
}
char bantu = 0;
bantu = kode[0];
// Pergeseran Index
for(int i = 0 ; i<=24 ; i++ ) {
kode[i] = kode[i+1];
}
kode[25] = bantu;
}
String c;
for(int w = 0; w
}
}
As for the implementation of the action button Decrypt are as follows:
private void btnDecryptActionPerformed(java.awt.event.ActionEvent evt) {
char [] kode = {'Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M' };
char [] abc = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
int ketemu=0;
char tampung = 0;
String plaintext = txtPlain.getText();
char[] ciphertext = new char[plaintext.length()];
if (!plaintext.equals(""))
txtPlain.setText(plaintext);
for(int w = 0; w
tampung = plaintext.toUpperCase().charAt(w) ;
for(int x = 0 ; x<=25 ; x++){
if(tampung == kode[x] ){
ketemu = x;
}
// else{ ketemu = -1; }
ciphertext[w] = abc[ketemu];
}
char bantu = 0;
bantu = abc[25];
// Pergeseran Index
for(int i = 25 ; i>=1 ; i-- ) {
abc[i] = abc[i-1];
}
abc[0] = bantu;
}
String c;
for(int w = 0; w
}
}
For the result, here is an example :
plain text = BEDA
chiper text = WYYR
keep trying and happy coding !
By : Mr.Stanza