PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith  >  Simple PHP Cipher Encryption  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Usage Example
Class: Simple PHP Cipher Encryption
Encrypt and decrypt text by mapping characters
Author: By
Last change:
Date: 2 years ago
Size: 1,964 bytes
 

Contents

Class file image Download
<?php
include('simplecipher.class.php');
$cipher = new simpleCipher();

$message = 'Message 106: This is a "secret" message, which includes some characters that will not be encrypted.';
$messageSave = $message;

$cMessage = $cipher->encryptMessage($message);
$cMessageSave = $cMessage;

echo
'<strong>encrypted:</strong> '.$cMessage.'<br>';

$tMessage = $cipher->decryptMessage($cMessage);

echo
'<strong>decrypted:</strong> '.$tMessage.'<hr>';

$message = 'Notice "the" and "the" and "the" are all different in the encrypted message, making the cipher difficult to break!!!';

$cMessage = $cipher->encryptMessage($message);

echo
'<strong>encrypted:</strong> '.$cMessage.'<br>';

$tMessage = $cipher->decryptMessage($cMessage);

echo
'<strong>decrypted:</strong> '.$tMessage.'<hr>';

echo
'<strong>We are now going to generate a new cipher map using the generateMap method</strong><br><br>';

$cipher->generateMap();

$message = 'Not only are characters mapped to replacements, the replacement character is also determined by its position in the message.';

$cMessage = $cipher->encryptMessage($message);

echo
'<strong>encrypted:</strong> '.$cMessage.'<br>';

$tMessage = $cipher->decryptMessage($cMessage);

echo
'<strong>decrypted:</strong> '.$tMessage.'<hr>';

echo
'<strong>We will now attempt to decrypt our first message<br><br></strong>';

echo
'<strong>message:</strong> '.$messageSave.'<br>';

echo
'<strong>encrypted:</strong> '.$cMessageSave.'<br>';

$tMessage = $cipher->decryptMessage($cMessageSave);

echo
'<strong>decrypted:</strong> '.$tMessage.'<br><br>';

echo
'<strong>which did not work because the map changed. We can encrypt it using the new map.</strong><br><br>';

$cMessage = $cipher->encryptMessage($messageSave);

echo
'<strong>encrypted:</strong> '.$cMessage.'<br>';

$tMessage = $cipher->decryptMessage($cMessage);

echo
'<strong>decrypted:</strong> '.$tMessage.'<hr>';
?>