PHP Classes

Simple PHP Cipher Encryption: Encrypt and decrypt text by mapping characters

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 72%Total: 191 All time: 8,573 This week: 555Up
Version License PHP version Categories
simple-cipher 1.0GNU General Publi...5PHP 5, Conversion
Description 

Author

This class can encrypt and decrypt text by mapping characters.

It can take a text string and encrypt it using two text strings that define which characters should be mapped to what other characters depending on the position of the character in the string.

The class can also do the opposite, i.e. take a previously encrypted string and invert the process to recover the original string.

The key strings with the characters to be mapped are configurable.

Picture of Dave Smith
  Performance   Level  
Name: Dave Smith is available for providing paid consulting. Contact Dave Smith .
Classes: 51 packages by
Country: United States United States
Age: 58
All time rank: 618 in United States United States
Week rank: 20 Up3 in United States United States Up
Innovation award
Innovation award
Nominee: 32x

Winner: 7x

Example

<?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>';
?>


Details

Class: simpleCipher Version: 1.0 11/17/2016 Copyright 2015 Wagon Trader, All Rights Reserved Description: This class will encrypt and decrypt text using a cipher that determines the replacement character by a mapped character and position in the message. Since the position is also considered, common words like 'the' will always be different in encrypted message. Files: simplecipher.class.php - Main class example.php - Simple application example Installation: Upload files to a web accessible location on your server (eg. public_html) Configuration: No configuration needed. If you use this in production, you will want to generate and save a new map. Simply run the following code in a script. <?php include('simplecipher.class.php'); $cipher = new simpleCipher(); echo $cipher->generateMap(true); ?> Copy the new map and use it to replace the $cipherMap variable in class. Usage: Refer to example.php file for a simple usage example. Refer to simplecipher.class.php for available methods and their usage. Changelog 1.0 Initial release

  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Usage Example
Accessible without login Plain text file license.txt Lic. License
Accessible without login Plain text file manual.txt Doc. Documentation
Plain text file simplecipher.class.php Class Main Class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:191
This week:0
All time:8,573
This week:555Up
User Ratings User Comments (2)
 All time
Utility:91%StarStarStarStarStar
Consistency:100%StarStarStarStarStarStar
Documentation:91%StarStarStarStarStar
Examples:75%StarStarStarStar
Tests:-
Videos:-
Overall:72%StarStarStarStar
Rank:177
 
Great job on custom encryption.
7 years ago (Anthony Amolochitis)
72%StarStarStarStar
Great job on custom encryption.
7 years ago (Anthony Amolochitis)
72%StarStarStarStar