You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

88 lines
3.0 KiB

<?php
namespace App\Libraries;
use Exception;
class AldLibrary
{
//private $fixedKey = session('nip');
public function generateKey($username) {
$time = time();
$time_mod = $time % 8; // Modulus time with 8
$fixed_phrase = "fixed_phrase"; // Frase tetap yang elu isi sendiri cuk!
$key_variations = [
"peopleDoCrazyThing", "JumpAround!", "ZarakiKenpachi", "UpOverAndGo!!!", "HeyThere..NiceToMeetY0u", "ToBeOrNotToBe!", "AreYouOkay?..", "paip123!OYEE"
];
$mod_key = $key_variations[$time_mod]; // Kata kunci berdasarkan hasil mod dari time()
// Menghitung jumlah ASCII dari username
$ascii_sum = 0;
for ($i = 0; $i < strlen($username); $i++) {
$ascii_sum += ord($username[$i]);
}
// Menentukan frase "genap" atau "ganjil"
$even_odd_phrase = ($ascii_sum % 2 == 0) ? "genap" : "ganjil";
// Menggabungkan semua kunci
$final_key = $username . $mod_key . $fixed_phrase . $even_odd_phrase;
// Mengembalikan kunci yang dihasilkan
return $final_key;
}
public function encryptMe($str, $username) {
$hasil = '';
$kunci = $this->generateKey($username);
for ($i = 0; $i < strlen($str); $i++) {
$karakter = substr($str, $i, 1);
$kuncikarakter = substr($kunci, ($i % strlen($kunci)), 1);
$karakter = chr(ord($karakter) + ord($kuncikarakter));
$hasil .= $karakter;
}
return urlencode(base64_encode($hasil));
}
public function decryptMe($str, $username) {
$str = base64_decode(urldecode($str));
$hasil = '';
$kunci = $this->generateKey($username);
for ($i = 0; $i < strlen($str); $i++) {
$karakter = substr($str, $i, 1);
$kuncikarakter = substr($kunci, ($i % strlen($kunci)), 1);
$karakter = chr(ord($karakter) - ord($kuncikarakter));
$hasil .= $karakter;
}
return $hasil;
}
public function encryptMeMawas($str) {
$hasil = '';
$salt = "generateFromDMPToMawasSince26082024";
$kunci = $this->generateKey($salt);
for ($i = 0; $i < strlen($str); $i++) {
$karakter = substr($str, $i, 1);
$kuncikarakter = substr($kunci, ($i % strlen($kunci)), 1);
$karakter = chr(ord($karakter) + ord($kuncikarakter));
$hasil .= $karakter;
}
return urlencode(base64_encode($hasil));
}
public function decryptMeMawas($str) {
$str = base64_decode(urldecode($str));
$hasil = '';
$salt = "generateFromDMPToMawasSince26082024";
$kunci = $this->generateKey($salt);
for ($i = 0; $i < strlen($str); $i++) {
$karakter = substr($str, $i, 1);
$kuncikarakter = substr($kunci, ($i % strlen($kunci)), 1);
$karakter = chr(ord($karakter) - ord($kuncikarakter));
$hasil .= $karakter;
}
return $hasil;
}
}