Here i’ll try to shared about coding at triple des and lzss compression.
This is the sample
<?php
include_once(“des/YI_DES.class.php”;
include_once(“lzss/YI_LZSS_Com.class.php”;
$enkrip = new YI_DES();
$kompres = new YI_Compress();
$password = $_POST['password'];
$temp = “temp/”;
$down = “download/”;
$enkrip -> cekSession(reg_userName);
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
if ($_POST['waktu'] > 240) set_time_limit(240); else set_time_limit($_POST['waktu']);
try {
$file_name = $_FILES['file']['name']; //Returns the Actual Name of the File.
$file_name = str_replace(“.”, “~”, $file_name);
$ext = substr($file_name, -3, 3);
copy($_FILES['file']['tmp_name'], $temp . $file_name); //Copy dari server temporary
if (filesize($temp . $file_name) <= 0) {
throw new exception(“Maaf, File tidak boleh kosong”;
}
$fr = fopen($temp . $file_name, “rb”;
$isi = fread($fr, filesize($temp . $file_name));
fclose($fr);
if ($password == “”{
throw new exception(“Maaf, password tidak boleh kosong”;
}
if (strlen($password) <= 7) {
throw new exception(“Maaf, password tidak boleh kurang dari 8 karakter”;
}
for ($i=0;$i<=strlen($password);$i++) {
if (strpos($password, chr(63), $i) AND strpos($password, chr(03), $i+1)) {
throw new exception(“Maaf, password tidak boleh menggunakan karakter ? dan _”;
}
}
$header = $kompres -> get_head_info($isi);
if ($header != “”{
throw new exception(“Maaf, file sudah dienkripsi”;
}
$waktu_mulai = microtime(TRUE);
$hasil_kompres = $kompres -> compress($temp . $file_name);
$hasil_enkrip = $enkrip -> des($password, $hasil_kompres, 1, 1, null);
//tulis file akhir proses kompresi dan enkripsi ditambah dengan header
// Format Header File : YI_DL$ext$key?
$hdr = “YI_DL” . $ext . $password . “?”;
$header = $enkrip -> enc_head($hdr);
$file_kom = $down . basename($file_name) . “.YI_DLZ”;
$akhir = strrev($header . “|” . $hasil_enkrip);
$fw = fopen($file_kom, “wb”;
fwrite($fw, $akhir);
fclose($fw);
$waktu_selesai = microtime(TRUE);
$waktu = $waktu_selesai – $waktu_mulai;
$file_asli = $temp . $file_name;
$file_proses = $down . $file_name . “.YI_DLZ”;
//laporan (proses, file asli, file proses, variabel hasil proses, waktu)
$kompres -> laporan(“enkrip”, $file_asli, $file_proses, $akhir, $waktu);
}
catch (Exception $e) {
$enkrip -> error($e);
}
}
else
$enkrip -> error2(“Maaf, Anda belum memasukkan file”;
?>
i’ve use this code, and if there is a some code is wrong plese tell me.
Thanks