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: 5 years ago
Size: 2,844 bytes


Class file image Download
//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!!!';
//include the class file
//instantiate the class with the image name and path
$imgkey = new imageKey($img,'testimage/');

$message ){
//if a new message was submitted then encrypt it
$encrypt = $imgkey->encryptMsg($message);
$encrypt ){
//otherwise decrypt the encrypted message if submitted
$decrypt = $imgkey->decryptMsg($encrypt);
        <meta charset="UTF-8">
        <title>Image Key Example</title>
        <form method="POST">
if( $errorMessage ){
<div style="padding:10px;border: solid thin red;"><?php echo $errorMessage;?></div>
<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>
if( $decrypt ){
            Decrypted message: <?php echo $decrypt;?><br>
        <div style="padding:10px;">You should only see a proper decryption if you selected the image it was encrypted with</div>