Commit d989ad37 authored by Kevin Merigot's avatar Kevin Merigot
Browse files

Initial commit

parents
========================================================
License(s)
--------------------------------------------------------
CC-BY-3.0-France : http://creativecommons.org/licenses/by/3.0/fr/legalcode
========================================================
Author(s)
--------------------------------------------------------
Kevin Merigot : http://www.mypersonnaldata.eu
========================================================
Support
--------------------------------------------------------
I do not provide any active support for this program.
But I'll be pleased to assist you if I can, so feel free to contact me.
========================================================
Contact
--------------------------------------------------------
You can contact me at this address : http://mypersonnaldata.eu/contact.html
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
var dictionaries = new Array();
dictionaries[0]="Le chien des Baskerville.txt";
dictionaries[1]="empire.txt";
dictionaries[2]="Les miserables.txt";
function encrypt()
{
jQuery.get('dictionary/'+dictionaries[$("#dictionary").val()], function(dicdata) {
var regex="/[^\\w|\\s|\\r]/gi";
dicdata.replace(eval(regex),"");
dicarray = dicdata.split(' ');
lengthdic = dicarray.length;
result='';
var enc_text=$("#enc_text").val();
enc_text = enc_text.replace(eval(regex),"");
words = enc_text.split(" ");
for (var i in words)
{
var word = words[i];
keys = array_keys(dicarray,word);
sizeofkeys = keys.length;
if (sizeofkeys > 0)
{
rand=Math.floor(Math.random()*sizeofkeys);
result+=keys[rand];
}
else
{
if ($("#heuristic").prop('checked'))
{
result += '(';
sizeofword = word.length;
for (i=0;i<sizeofword;i++)
{
o=ord(word[i]);
result+=o;
if (i<sizeofword-1)
{
result+='.';
}
}
result+=')';
}
else
{
result += '?';
}
}
result+='/';
}
$("#result").text(result);
});
}
function decrypt()
{
jQuery.get('dictionary/'+dictionaries[$("#dictionary").val()], function(dicdata) {
var regex="/[^\\w|\\s|\\r]/gi";
dicdata.replace(eval(regex),"");
dicarray = dicdata.split(' ');
dwords = $("#enc_text").val().split('/');
result='';
for (var i in dwords)
{
dword = dwords[i];
if (dword != '')
{
if (dword.indexOf('(') == 0)
{
replaceregex = "/[\(\)]/g";
dword=dword.replace(eval(replaceregex),'');
chars = dword.split('.');
for (var c in chars)
{
dchar=chars[c];
result+=chr(dchar);
}
result+=' ';
}
else if (dword == '?')
{
result+='?';
}
else
{
result+=dicarray[dword];
}
result+=' ';
}
}
$("#result").text(result);
});
}
// below are the different utility functions from http://phpjs.org
function array_keys (input, search_value, argStrict) {
// http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + input by: Brett Zamir (http://brett-zamir.me)
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: jd
// + improved by: Brett Zamir (http://brett-zamir.me)
// + input by: P
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// * example 1: array_keys( {firstname: 'Kevin', surname: 'van Zonneveld'} );
// * returns 1: {0: 'firstname', 1: 'surname'}
var search = typeof search_value !== 'undefined',
tmp_arr = [],
strict = !!argStrict,
include = true,
key = '';
if (input && typeof input === 'object' && input.change_key_case) { // Duck-type check for our own array()-created PHPJS_Array
return input.keys(search_value, argStrict);
}
for (key in input) {
if (input.hasOwnProperty(key)) {
include = true;
if (search) {
if (strict && input[key] !== search_value) {
include = false;
}
else if (input[key] != search_value) {
include = false;
}
}
if (include) {
tmp_arr[tmp_arr.length] = key;
}
}
}
return tmp_arr;
}
function ord (string) {
// http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Onno Marsman
// + improved by: Brett Zamir (http://brett-zamir.me)
// + input by: incidence
// * example 1: ord('K');
// * returns 1: 75
// * example 2: ord('\uD800\uDC00'); // surrogate pair to create a single Unicode character
// * returns 2: 65536
var str = string + '',
code = str.charCodeAt(0);
if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
var hi = code;
if (str.length === 1) {
return code; // This is just a high surrogate with no following low surrogate, so we return its value;
// we could also throw an error as it is not a complete character, but someone may want to know
}
var low = str.charCodeAt(1);
return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
}
if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
return code; // This is just a low surrogate with no preceding high surrogate, so we return its value;
// we could also throw an error as it is not a complete character, but someone may want to know
}
return code;
}
function chr (codePt) {
// http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Brett Zamir (http://brett-zamir.me)
// * example 1: chr(75);
// * returns 1: 'K'
// * example 1: chr(65536) === '\uD800\uDC00';
// * returns 1: true
if (codePt > 0xFFFF) { // Create a four-byte string (length 2) since this code point is high
// enough for the UTF-16 encoding (JavaScript internal use), to
// require representation with two surrogates (reserved non-characters
// used for building other characters; the first is "high" and the next "low")
codePt -= 0x10000;
return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 + (codePt & 0x3FF));
}
return String.fromCharCode(codePt);
}
========================================================
License(s)
--------------------------------------------------------
CC-BY-3.0-France : http://creativecommons.org/licenses/by/3.0/fr/legalcode
========================================================
Author(s)
--------------------------------------------------------
Kevin Merigot : http://www.mypersonnaldata.eu
========================================================
Support
--------------------------------------------------------
I do not provide any active support for this program.
But I'll be pleased to assist you if I can, so feel free to contact me.
========================================================
Contact
--------------------------------------------------------
You can contact me at this address : http://mypersonnaldata.eu/contact.html
<?php
// check
$type=$_POST['type'];
$dic=$_POST['dictionary'];
$text=$_POST['text'];
$heuristic=$_POST['heuristic'];
$shift=$_POST['shift'];
$noiseD=$_POST['day'];
$noiseM=$_POST['month'];
$noiseY=$_POST['year'];
if (!is_null($type) && !is_null($dic) && is_numeric($type) && is_numeric($dic) && (is_null($heuristic) || $heuristic==='10') && is_numeric($shift))
{
if (!(is_numeric($noiseD) && is_numeric($noiseM) && is_numeric($noiseY)))
{
$noiseD=0;
$noiseM=0;
$noiseY=0;
}
$dictionaries = array('Le chien des Baskerville.txt','empire.txt','Les miserables.txt');
$expreg='/[^\w|\s|\r]/';
$mydic = file_get_contents('dictionary/'.$dictionaries[$dic]);
$mydic = preg_replace($expreg,'',$mydic);
$dicarray = explode(' ',$mydic);
$lengthdic = sizeof($dicarray);
$result='';
$heuristic = $heuristic==10;
$noise = $noiseD > 0 && $noiseM > 0 && $noiseY > 0;
if ($type==1)
{
$encode = preg_replace($expreg,'',$text);
$crypt = explode(' ',$encode);
$incomplete=false;
$cptD=0;
$cptM=0;
foreach ($crypt as $word)
{
$keys = array_keys($dicarray,$word);
$size = sizeof($keys);
$position=0;
if($noise && $cptD % $noiseD == 1)
{
$nbNoise = abs($noiseM + $cptM - $noiseD);
for ($i=0;$i<$nbNoise;$i++)
{
$result.=rand(1,$lengthdic).'/';
$cptM++;
}
}
if ($size > 1)
{
$position = rand(0,$size-1);
}
if ($size == 0)
{
if ($heuristic)
{
$result.='(';
for ($i=0;$i<strlen($word);$i++)
{
$ord=ord($word[$i])+$shift;
$result.=$ord;
if ($i<strlen($word)-1)
{
$result.='.';
}
}
$result.=')';
}
else
{
$result.='?';
}
$incomplete=true;
}
else
{
$result.=$keys[$position];
}
$result.='/';
$cptD++;
}
}
elseif ($type==2)
{
$decode_array = explode('/',$text);
$cptD=0;
$cptM=0;
$nbNoise=0;
$go=true;
foreach ($decode_array as $key)
{
$go=true;
if($noise && $cptD % $noiseD == 0)
{
$nbNoise = abs($noiseM + $cptM - $noiseD);
$go=true;
}
elseif ($nbNoise > 0)
{
$go=false;
$nbNoise--;
$cptM++;
}
if ($go)
{
if (preg_match('/\(.*\)/',$key))
{
$key=preg_replace('/[\(\)]/','',$key);
$chars = explode('.',$key);
foreach ($chars as $char)
{
$result.=chr($char-$shift);
}
$result.=' ';
}
else
{
$result.=$dicarray[$key].' ';
}
$cptD++;
}
}
}
}
?>
<h1>Result</h1>
<pre><?php echo $result; ?></pre>
<a href="sherlock.php">Back</a>
<?php
// List of the dictionaries titles
$dictionaries = array('Le chien des Baskerville - Sir Arthur Conan Doyle','L\'Empire romain apr&egrave;s la paix de l\'&eacute;glise - Cte de Montalbert','Les Mis&eacute;rables / Livre Premier / Tome 1 - Victor Hugo');
?>
<h1>Encode</h1>
<form action="process.php" method="post">
<input type="hidden" name="type" value="1" />
<select name="dictionary">
<?php
foreach ($dictionaries as $key=>$value)
{
?>
<option value="<?php echo $key;?>"><?php echo $value;?></option>
<?php
}
?>
</select><br />
<input type="checkbox" name="heuristic" value="10" /> Coder m&ecirc;me les mots n'existant pas dans le dictionnaire avec un d&eacute;calage de : <input type="text" value="0" name="shift"/><br />
Ajouter du bruit : <select name="day"><option value="">--</option>
<?php
for ($i=1;$i<=31;$i++)
{
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>/
<select name="month"><option value="">--</option>
<?php
for ($i=1;$i<=12;$i++)
{
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>/
<select name="year"><option value="">--</option>
<?php
for ($i=1920;$i<=2000;$i++)
{
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
<br />
<textarea name="text" cols="160" rows="12"></textarea>
<input type="submit" value="OK" />
</form>
<h1>Decode</h1>
<form action="process.php" method="post">
<input type="hidden" name="type" value="2" />
<select name="dictionary">
<?php
foreach ($dictionaries as $key=>$value)
{
?>
<option value="<?php echo $key;?>"><?php echo $value;?></option>
<?php
}
?>
</select><br />
<input type="checkbox" name="heuristic" value="10" /> D&eacute;coder m&ecirc;me les mots n'existant pas dans le dictionnaire avec un d&eacute;calage de : <input type="text" value="0" name="shift"/><br />
Retirer le bruit : <select name="day"><option value="">--</option>
<?php
for ($i=1;$i<=31;$i++)
{
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>/
<select name="month"><option value="">--</option>
<?php
for ($i=1;$i<=12;$i++)
{
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>/
<select name="year"><option value="">--</option>
<?php
for ($i=1920;$i<=2000;$i++)
{
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
<br />
<textarea name="text" cols="160" rows="12"></textarea>
<input type="submit" value="OK" />
</form>
<html>
<head>
<title>Sherlock Crypto : A Javascript encryption tool</title>
<link rel="stylesheet" type="text/css" href="/css/main.css" />
</head>
<body>
<script src="js/sherlock-crypto.js" charset="utf-8" type="text/javascript"></script>
<script src="js/jquery.min.js"></script>
<?php
$dictionaries = array('Le chien des Baskerville - Sir Arthur Conan Doyle','L\'Empire romain apr&egrave;s la paix de l\'&eacute;glise - Cte de Montalbert','Les Mis&eacute;rables / Livre Premier / Tome 1 - Victor Hugo');
?>
<div class="center">
<div class="block header">
Sherlock Crypto : A Javascript encryption tool
</div>
<div class="block content">
<select name="dictionary" id="dictionary">
<?php
foreach ($dictionaries as $key=>$value)
{
?>
<option value="<?php echo $key;?>"><?php echo $value;?></option>
<?php
}
?>
</select><br />
<input type="checkbox" name="heuristic" id="heuristic" value="10" /> Encrypt even the words not found in the dictionary
<br />
<textarea name="enc_text" id="enc_text" cols="160" rows="12"></textarea>
<br />
<input type="button" value="Encrypt" onclick="encrypt();"/> <input type="button" value="Decrypt" onclick="decrypt();"/>
<pre id="result">Result</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment