Membaca Flowchart [Program Untuk Menyandikan Suatu Kalimat]
20.12.00ﺑﺴﻢﷲﺍﻠﺮﺤﻤﻦﺍﻠﺮﺤﻴﻢ
Sandi SBB :
INPUT / MASUKAN :
1. sandi = st see,eaea abaitrblr sslllmadehl u aask euanr,sjus
2. sandi = jni ktanua ddnti krk uyrspniaeneeoif uekklnt
3. sandi = jni kranua ddnti omk uyrspniaenifaif uekkntt
4. sandi = stnr!sjneaea!adehl u aaa sslllm! abaitrblrdsk eua! see us
KALAU MAU MEMBUAT SANDI SENDIRI
SILAKAN RUNNING FILE chiper.java KEMUDIAN MASUKKAN
KALIMAT YANG INGIN ANDA SANDIKAN.
Conto ne :
import java.util.Scanner;
import java.io.*;
class chiper {
public static void main(String[] args) {
int n, panj, kel, i, incr1, incr2;
String plain, chiper="";
Scanner nilai = new Scanner(System.in);
System.out.println("Masukkan kalimat --> ");
plain = nilai.nextLine();
n = 4;
panj = plain.length();
kel = 2 * n - 2;
for (i = 0; i < 4; i++) {
incr1 = kel - 2 * i;
incr2 = 2 * i;
n = i;
chiper = chiper + plain.charAt(i);
while (n < panj) {
n = n + incr1;
if ((n < panj) && (incr1 != 0))
chiper = chiper + plain.charAt(n);
n = n + incr2;
if ((n < panj) && (incr2 != 0))
chiper = chiper + plain.charAt(n);
}
}
System.out.println("Sandi --> " + chiper);
}
}
=========================================================
Source Code dari flowchart di atas : ?????? [nih udah jadi]
package prak10;
import java.util.Scanner;
public class Prak10 {
public static void main(String[] args) {
int a, p, n, kel, i, j, m, L, inc1, inc2;
String sandi, teks;
Scanner input = new Scanner(System.in);
System.out.printf("Masukkan sandi => ");
sandi=input.nextLine();
p = sandi.length();
String kata[]=new String[1000];
n=4;
kel=2*n-2;
i=0;
j=0;
do{
inc1=kel-2*i;
inc2=2*i;
m=i;
do{
m=m+inc1;
L=m-inc1;
if(m<p && inc1!=0){
kata[m]=Character.toString(sandi.charAt(i+j+1));
kata[L]=Character.toString(sandi.charAt(i+j));
j=j+1;
}
if(inc1==0){
kata[m]=Character.toString(sandi.charAt(i+j));
}
m=m+inc2;
if(m<p && inc2!=0){
kata[m]=Character.toString(sandi.charAt(i+j+1));
j=j+1;
}
}while(m<p);
i=i+1;
}while(i<n);
teks= " ";
i=0;
while(i<p){
teks=teks+kata[i];
i=i+1;
}
System.out.print(teks);
}
}
0 komentar