PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith   Image Key Cypher   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Usage example
Class: Image Key Cypher
Encrypt and decrypt text using images for the key
Author: By
Last change:
Date: 6 years ago
Size: 2,844 bytes
 

Contents

Class file image Download
<?php
//define some empty variables used in the markup
$errorMessage = '';
$encrypt = '';
$decrypt = '';

//process the submitted form
if( isset($_REQUEST['formSubmit']) ){
   
$img = ( empty($_REQUEST['img']) ) ? null : $_REQUEST['img'];
   
$message = $_REQUEST['message'];
   
$encrypt = $_REQUEST['encrypt'];

    if( empty(
$img) ){
       
//set error if image name not submitted
       
$errorMessage = 'You must select an image!!!';
    }else{
       
//include the class file
       
require('imagekey.class.php');
       
//instantiate the class with the image name and path
       
$imgkey = new imageKey($img,'testimage/');

        if(
$message ){
           
//if a new message was submitted then encrypt it
           
$encrypt = $imgkey->encryptMsg($message);
        }elseif(
$encrypt ){
           
//otherwise decrypt the encrypted message if submitted
           
$decrypt = $imgkey->decryptMsg($encrypt);
        }
    }
}
?>
<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Image Key Example</title>
    </head>
    <body>
        <form method="POST">
<?php
if( $errorMessage ){
?>
<div style="padding:10px;border: solid thin red;"><?php echo $errorMessage;?></div>
<?php
}
?>
<div style="padding:10px;">Select an image and either enter a new message or test decrypting the encrypted message</div>
            <div style="margin:20px;float:left;"><img src="testimage/attach.png"><br><input type="radio" name="img" value="attach.png"></div>
            <div style="margin:20px;float:left;"><img src="testimage/camera.png"><br><input type="radio" name="img" value="camera.png"></div>
            <div style="margin:20px;float:left;"><img src="testimage/cancel.png"><br><input type="radio" name="img" value="cancel.png"></div>
            <div style="margin:20px;float:left;"><img src="testimage/cross.png"><br><input type="radio" name="img" value="cross.png"></div>
            <div style="margin:20px;float:left;"><img src="testimage/stop.png"><br><input type="radio" name="img" value="stop.png"></div>
            <div style="clear:both;"></div>
            <div>New message:<br><textarea name="message" style="width:500px;height:100px;"></textarea></div>
            <div>Encrypted message:<br><textarea name="encrypt" style="width:500px;height:150px;"><?php echo $encrypt;?></textarea></div>
            <div><input type="hidden" name="formSubmit" value="1"><input type="submit" value="Go"></div>
        </form>
<?php
if( $decrypt ){
?>
<hr>
        <div>
            Decrypted message: <?php echo $decrypt;?><br>
        </div>
        <div style="padding:10px;">You should only see a proper decryption if you selected the image it was encrypted with</div>
<?php
}
?>
</body>
</html>