Skip to content
Snippets Groups Projects
Commit 5e43bd3a authored by daniarherikurniawan's avatar daniarherikurniawan
Browse files

update algorithm

parent 54adefd0
No related merge requests found
const MAX_RAND = 50;
const MAX_RAND = 500;
const MIN_RAND = 0;
......@@ -74,4 +74,5 @@ function caesarShift(text, shift) {
else result += text.charAt(i); // Copy
}
return result;
}
\ No newline at end of file
}
<?php
session_start();
define ("MAX_INT",50);
define ("MAX_INT",500);
// include 'mainviewer.php';
......@@ -76,7 +76,7 @@
// echo $shared_key; echo " ";
$stmt = $con->prepare("UPDATE user SET shared_key=? WHERE User_Id=?");
$stmt->bind_param("ii", $sharedKey, $_SESSION["myId"]);
$_SESSION["shared_key"] = $sharedKey;
$stmt->execute();
$stmt->close();
......
......@@ -135,9 +135,9 @@
if (validateDate()){
var shared_key = deffiehelman();
// document.getElementById('Judul').textContent =
document.getElementById('Judul').value = (caesarShift(document.getElementById('Judul').value, shared_key%25));
document.getElementById('Konten').value = (caesarShift(document.getElementById('Konten').value, shared_key%25));
// document.getElementById('Judul').value = (caesarShift(document.getElementById('Judul').value, shared_key%25));
// document.getElementById('Konten').value = (caesarShift(document.getElementById('Konten').value, shared_key%25));
return true;
}else{
return false;
}
......
......@@ -2,10 +2,11 @@
session_start();
if (isset($_SESSION["isLogin"]) && (isset($_POST['csrf_token']) && $_POST['csrf_token'] === $_SESSION['csrf_token'])){
include 'mainviewer.php';
// var_dump();
$Judul = $_POST['Judul'];
$Tanggal = $_POST['Tanggal'];
$creatorid = $_SESSION["myId"];
$Konten = $_POST['Konten'];
$Konten = $_POST['Konten'];// caesarDecode ( $_POST['Konten'], (int)$_SESSION["shared_key"]) ;
$target_dir = "uploads/";
$target_file = $target_dir.basename($_FILES["image"]["name"]);
......@@ -40,21 +41,18 @@ if (isset($_SESSION["isLogin"]) && (isset($_POST['csrf_token']) && $_POST['csrf_
} else {
if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.<br>";
<<<<<<< HEAD
$con = phpsqlconnection();
=======
$con = phpsqlconnection();
>>>>>>> df17127f283f68ad29758e0e77f1885ac2eb0ed3
$stmt = $con->prepare("INSERT INTO post (Post_Id, Creator_Id, Title, Date, Contents, Image)
VALUES (NULL,?,?,?,?,?)");
$stmt->bind_param('issss', $creatorid, $Judul, $Tanggal, $Konten, $target_file);
$stmt->execute();
$status = $stmt->execute();
// $result = $stmt->get_result();
// $sql = "INSERT INTO post (Post_Id, Creator_Id, Title, Date, Contents, Image)
// VALUES (NULL".",".$creatorid.","."'".$Judul."'".","."'".$Tanggal."'".","."'".$Konten."'".","."'".$target_file."')";
if ($stmt->execute()) {
if ($status) {
// echo "Huba";
header("Location: index.php");
} else {
......@@ -62,36 +60,36 @@ if (isset($_SESSION["isLogin"]) && (isset($_POST['csrf_token']) && $_POST['csrf_
}
die();
<<<<<<< HEAD
} else {
echo "Sorry, there was an error uploading your file.<br>";
}
}
=======
} else {
echo "Sorry, there was an error uploading your file.<br>";
}
}
>>>>>>> df17127f283f68ad29758e0e77f1885ac2eb0ed3
}else{
header("Location: login.php"); /* Redirect browser */
}
function decryptCaesar($encrypted_text, $key){
$alphabet=array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
//positions of the letters in alphabet
$flip=array_flip($alphabet);
$decrypted_text='';
for ($i=0; $i<$n; $i++)
//decryption
$decrypted_text.=$alphabet[(26+$flip[$encrypted_text[$i]]-$key)%26];
return $decrypted_text;
}
function caesarDecode( $message, $key ){
$key = $key%25;
$ciphertext = "";
$ascii_a = ord( 'a' );
$ascii_z = ord( 'z' );
$ascii_A = ord( 'A' );
$ascii_Z = ord( 'Z' );
while( strlen( $plaintext ) ){
$char = ord( $plaintext );
if( $char >= $ascii_a && $char <= $ascii_z ){
$char = ( ( $key + $char + $ascii_a ) % 26 ) ;
}else if( $char >= $ascii_A && $char <= $ascii_Z ){
$char = ( ( $key + $char + $ascii_A ) % 26 ) ;
}
$plaintext = substr( $plaintext, 1 );
$ciphertext .= chr( $char );
}
return "$ciphertext";
}
?>
\ No newline at end of file
code/uploads/f.jpg

137 KiB

code/uploads/g.jpg

45.3 KiB

code/uploads/meme_mastin3.jpg

36.3 KiB

0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment