Source Code Kriptografi Rot13 Menggunakan Java
package kriptografiTonnyAray;
public class ROT13 {
public static void main(String[] args) {
String plain = "kriptografi tonny aray";
String key = "10:15PM";
ROT13 x = new ROT13();
String chipper = x.enkripsi(plain, key);
System.out.println("Plain TextLp2maray:\t" + plain);
System.out.println("Key TextLp2maray:\t" + key);
System.out.println("Chipper TextLp2maray:\t" + chipper);
String decrypt = x.dekripsi(chipper, key);
System.out.println("Decrypt Text:\t" + decrypt);
}
String enkripsi(String p, String k) {
// String l = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#&%*()-_=:,.'?/$^ ";
String[] ar = k.split(":");
String jam = ar[0];
String menit = ar[1];
int ijam = Integer.parseInt(jam);
int imenit = Integer.parseInt(menit);
int pms = 256;//l.length();
int pln = p.length();
int ky = k.length();
String gab = "";
for (int i = 0; i < pln; i++) {
if (i % 2 == 0) {
int ke = (int)p.charAt(i);//l.indexOf(p.charAt(i));
int posbaru = (ke + ijam) % pms;
char cnew = (char)posbaru;//l.charAt(posbaru);
System.out.println("P" + i + "=" + p.charAt(i) + "=huruf ke-" + ke + "+" + ijam + "=" + posbaru + "=" + cnew);
gab += cnew;
} else {
int ke = (int)p.charAt(i);//l.indexOf(p.charAt(i));
int posbaru = (ke + imenit) % pms;
char cnew = (char)posbaru;//l.charAt(posbaru);
System.out.println("L" + i + "=" + p.charAt(i) + "=huruf ke-" + ke + "+" + imenit + "=" + posbaru + "=" + cnew);
gab += cnew;
}
}
return gab;
}
//==================================================================================
String dekripsi(String p, String k) {
// String l = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#&%*()-_=:,.'?/$^ ";
String[] ar = k.split(":");
String jam = ar[0];
String menit = ar[1];
int ijam = Integer.parseInt(jam);
int imenit = Integer.parseInt(menit);
int pms = 256;//l.length();
int pln = p.length();
int ky = k.length();
String gab = "";
for (int i = 0; i < pln; i++) {
if (i % 2 == 0) {
int ke = (int)p.charAt(i);//l.indexOf(p.charAt(i));
int posbaru = ((ke - ijam) + pms) % pms;
char cnew = (char)posbaru;//l.charAt(posbaru);
System.out.println("P" + i + "=" + p.charAt(i) + "=huruf ke-" + ke + "+" + ijam + "=" + posbaru + "=" + cnew);
gab += cnew;
} else {
int ke = (int)p.charAt(i);//l.indexOf(p.charAt(i));
int posbaru = ((ke - imenit) + pms) % pms;
char cnew = (char)posbaru;//l.charAt(posbaru);
System.out.println("L" + i + "=" + p.charAt(i) + "=huruf ke-" + ke + "+" + imenit + "=" + posbaru + "=" + cnew);
gab += cnew;
}
}
return gab;
}
}
Posting Komentar untuk "Source Code Kriptografi Rot13 Menggunakan Java"