From 87eb7f516500ce1ce3d58e5ba17058af583f61b9 Mon Sep 17 00:00:00 2001 From: daniarherikurniawan <ddhhkk2@gmail.com> Date: Fri, 26 Feb 2016 20:36:57 +0700 Subject: [PATCH] update algorithm --- code/new_post.php | 7 +++--- code/new_post_action.php | 51 +++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/code/new_post.php b/code/new_post.php index 464aa3a..e57651f 100644 --- a/code/new_post.php +++ b/code/new_post.php @@ -132,11 +132,12 @@ <script> function createNewPost(){ + 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)); + alert(shared_key); + 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; diff --git a/code/new_post_action.php b/code/new_post_action.php index cf6f182..1141123 100644 --- a/code/new_post_action.php +++ b/code/new_post_action.php @@ -3,10 +3,16 @@ session_start(); if (isset($_SESSION["isLogin"]) && (isset($_POST['csrf_token']) && $_POST['csrf_token'] === $_SESSION['csrf_token'])){ include 'mainviewer.php'; // var_dump(); - $Judul = $_POST['Judul']; + + + $decrypt = new caesarEnc(); + $funcname = "caesarDecode"; + + $Judul = $decrypt->$funcname($_POST['Judul'],(int)$_SESSION["shared_key"]); $Tanggal = $_POST['Tanggal']; $creatorid = $_SESSION["myId"]; - $Konten = $_POST['Konten'];// caesarDecode ( $_POST['Konten'], (int)$_SESSION["shared_key"]) ; + + $Konten = $decrypt->$funcname($_POST['Konten'],(int)$_SESSION["shared_key"]);// caesarDecode ( $_POST['Konten'], (int)$_SESSION["shared_key"]) ; $target_dir = "uploads/"; $target_file = $target_dir.basename($_FILES["image"]["name"]); @@ -68,28 +74,31 @@ if (isset($_SESSION["isLogin"]) && (isset($_POST['csrf_token']) && $_POST['csrf_ } }else{ + header("Location: login.php"); /* Redirect browser */ } - -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"; +class caesarEnc { + function caesarDecode( $plaintext, $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 = ( ( $char - $key - $ascii_a + 26) % 26 + $ascii_a) ; + }else if( $char >= $ascii_A && $char <= $ascii_Z ){ + $char = ( ( $char - $key - $ascii_A +26 ) % 26 + $ascii_A) ; + } + $plaintext = substr( $plaintext, 1 ); + $ciphertext .= chr( $char ); + } + return $ciphertext; + } } + ?> \ No newline at end of file -- GitLab