Kamis, 15 Januari 2009

Source code Java enkripsi file sederhana

Berikut enkripsi file sederhana misal anda punya file yang berisi karakter abc disimpan dalam file coba1.txt kemudian anda ingin mengenkripsikan dengan mengganti karakter abc menjadi bcd dan disimpan dengan nama file lain...

Berikut listing code-nya :
==================================================================================
import java.io.*;

public class EnkripsiFile
{
public EnkripsiFile(String sumber, String tujuan, int angka)
{
FileInputStream fis = null;
try
{
fis = new FileInputStream(sumber);
} catch(FileNotFoundException ex)
{
System.out.println("File Not Found");
}

try
{
char data;
int temp, tampung;
FileOutputStream fos;
fos = new FileOutputStream(tujuan);
do
{
//ingat fis.reaad() mengambil kode unicode per karakter
temp = fis.read();
tampung = temp+angka;
//ubah kode ascii jadi huruf
data = (char)tampung;
try
{
fos.write(data);
} catch(FileNotFoundException ex)
{
System.out.println("File cannot opened for writing");
}

} while(temp != -1);
} catch(IOException ex)
{
System.out.println("Problem");
}
}

public static void main(String args[]) throws IOException
{
System.out.println("How many number do you wanto skip ?");
String Strangka;
BufferedReader bl = new BufferedReader(new InputStreamReader(System.in));
Strangka = bl.readLine();

//cara konvert dari kelas String ke tipe integer
int angka = Integer.parseInt(Strangka);

System.out.println("What is the name of the source file ?");
String sumber;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
sumber = br.readLine();
System.out.println("Enter data to write to "+sumber+"...");
System.out.println("What is the name of the aim file ?");
String tujuan;
BufferedReader bd = new BufferedReader(new InputStreamReader(System.in));
tujuan = bd.readLine();
System.out.println("Enter data to write to "+tujuan+"...");

new EnkripsiFile(sumber,tujuan,angka);

}
}

1 komentar:

quartillawagman mengatakan...

Borgata Hotel Casino & Spa - Las Vegas - GoyangFC
Borgata Hotel Casino & Spa is aramexchangeb.com the latest and best way 룰렛사이트 to 플레이포커 experience Vegas and get a taste of it bitcasino all while enjoying it every day. 잭팟 시티 We have over 3,000