Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit ec7cd32d5479231e8bbb56ec083f536458d132b2 0 parents
@HazAT authored
0  README
No changes.
98 examples/example1/index.html
@@ -0,0 +1,98 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Example 1</title>
+ <style type="text/css">
+ html,body {
+ margin:0;
+ padding:0;
+ font-family:Tahoma;
+ font-size:12px;
+ }
+ input,textarea,select {
+ font-family:Tahoma;
+ font-size:12px;
+ }
+ </style>
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+ <script type="text/javascript" src="../../jquery.jcryption-1.1.js" ></script>
+ <script type="text/javascript">
+
+ $.fn.fillInForm = function() {
+ $(this).find("a[href='#fillWithSamples']").click(function() {
+ $parentForm = $(this).closest("form");
+ $parentForm.find(":radio:eq(0)").attr("checked","checked");
+ $parentForm.find("input[name='Firstname']").val("John");
+ $parentForm.find("input[name='Lastname']").val("Wayne");
+ $parentForm.find("input[name='Email']").val("john@wayne.cc");
+ $parentForm.find(":checkbox:eq(2)").attr("checked","checked");
+ $parentForm.find("select[name='age']").val("over 30");
+ $parentForm.find("select[name='likes[]']").children("option:eq(0),option:eq(1),option:eq(3)").attr("selected","selected")
+ return false;
+ });
+ };
+
+ $(function() {
+ // Just the from filling code
+ $("#normal").fillInForm();
+ $(":input").removeAttr("disabled");
+ // --------------------------
+
+ $("#normal").jCryption();
+ });
+ </script>
+ </head>
+
+ <body>
+ <form id="normal" class="general" action="main.php" method="post"> <fieldset>
+
+ <strong><a href="#fillWithSamples" style="color:#000000;">fill with samples &raquo;</a></strong>
+ <table border="0" cellspacing="5" cellpadding="0">
+ <tbody>
+ <tr>
+ <td>Sex:</td>
+ <td><input class="radio" name="Sex" type="radio" value="male" />Male
+
+ <input class="radio" name="Sex" type="radio" value="female" />Female</td>
+ </tr>
+ <tr>
+ <td>Firstname:</td>
+ <td><input class="text" name="Firstname" type="text" /></td>
+ </tr>
+ <tr>
+ <td>Lastname:</td>
+ <td><input class="text" name="Lastname" type="text" /></td>
+ </tr>
+ <tr>
+ <td>E-Mail:</td>
+ <td><input class="text" name="Email" type="text" /></td>
+ </tr>
+ <tr>
+ <td>What would you like to eat?</td>
+ <td><input class="checkbox" name="Food[]" type="checkbox" value="pizza" />Pizza
+
+ <input class="checkbox" name="Food[]" type="checkbox" value="hamburger" />Hamburger
+
+ <input class="checkbox" name="Food[]" type="checkbox" value="salad" />Salad
+
+ <input class="checkbox" name="Food[]" type="checkbox" value="steak" />Steak</td>
+ </tr>
+ <tr>
+ <td>Age:</td>
+ <td><select name="age"> <option value="under 18">under 18</option> <option value="over 18">over 18</option> <option value="over 30">over 30</option> </select></td>
+ </tr>
+ <tr valign="top">
+ <td valign="top">I like (you can select more than one):</td>
+ <td><select name="likes[]" size="5" multiple="multiple"> <option value="Michael Jackson">Michael Jackson</option> <option value="rainy wheater">rainy wheater</option> <option value="a hot summer">a hot summer</option> <option value="small cats">small cats</option> <option value="funny movies">funny movies</option> <option value="I like everything">I like everything</option> </select></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td><input title="Submit" alt="Submit" name="submitButton" type="submit" value="Submit" class="submit" /> <input title="Reset" alt="Reset" name="reset" type="reset" value="Reset" /></td>
+ </tr>
+ </tbody>
+ </table>
+ </fieldset>
+ </form>
+ </body>
+</html>
47 examples/example1/main.php
@@ -0,0 +1,47 @@
+<?php
+session_start();
+require_once("../../jCryption-1.1.php");
+$keyLength = 256;
+$jCryption = new jCryption();
+if(isset($_GET["generateKeypair"])) {
+ $keys = $jCryption->generateKeypair($keyLength);
+ $_SESSION["e"] = array("int" => $keys["e"], "hex" => $jCryption->dec2string($keys["e"],16));
+ $_SESSION["d"] = array("int" => $keys["d"], "hex" => $jCryption->dec2string($keys["d"],16));
+ $_SESSION["n"] = array("int" => $keys["n"], "hex" => $jCryption->dec2string($keys["n"],16));
+
+ echo '{"e":"'.$_SESSION["e"]["hex"].'","n":"'.$_SESSION["n"]["hex"].'","maxdigits":"'.intval($keyLength*2/16+3).'"}';
+} else {
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>Result</title>
+<style type="text/css">
+html,body {
+ margin:0;
+ padding:0;
+ font-family:Tahoma;
+ font-size:12px;
+}
+</style>
+</head>
+<body>
+
+<p><strong>orignial POST:</strong> <br/><?php print_r($_POST); ?></p>
+<?php
+$var = $jCryption->decrypt($_POST['jCryption'], $_SESSION["d"]["int"], $_SESSION["n"]["int"]);
+unset($_SESSION["e"]);
+unset($_SESSION["d"]);
+unset($_SESSION["n"]);
+parse_str($var,$result);
+?>
+
+<p><strong>decrypted POST:</strong> <br/><?php print_r($result); ?></p>
+
+</body>
+</html>
+
+<?php
+}
+?>
104 examples/example2/index.html
@@ -0,0 +1,104 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Example 2</title>
+ <style type="text/css">
+ html,body {
+ margin:0;
+ padding:0;
+ font-family:Tahoma;
+ font-size:12px;
+ }
+ input,textarea,select {
+ font-family:Tahoma;
+ font-size:12px;
+ }
+ </style>
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+ <script type="text/javascript" src="../../jquery.jcryption-1.1.js" ></script>
+ <script type="text/javascript">
+
+ $.fn.fillInForm = function() {
+ $(this).find("a[href='#fillWithSamples']").click(function() {
+ $parentForm = $(this).closest("form");
+ $parentForm.find(":radio:eq(0)").attr("checked","checked");
+ $parentForm.find("input[name='Firstname']").val("John");
+ $parentForm.find("input[name='Lastname']").val("Wayne");
+ $parentForm.find("input[name='Email']").val("john@wayne.cc");
+ $parentForm.find(":checkbox:eq(2)").attr("checked","checked");
+ $parentForm.find("select[name='age']").val("over 30");
+ $parentForm.find("select[name='likes[]']").children("option:eq(0),option:eq(1),option:eq(3)").attr("selected","selected")
+ return false;
+ });
+ };
+
+ $(function() {
+
+ var $status = $('<div id="status" style="margin-top:15px;"><img src="loading.gif" alt="Loading..." title="Loading..." style="margin-right:15px;" /><span>Encrypting</span></div>').hide();
+ $("#submitButton").parent().append($status);
+
+ $("#callbackForm").jCryption({
+ beforeEncryption:function() {
+ $status.show();
+ return true;
+ }
+ }).find("fieldset").fillInForm();
+
+ $(":input").removeAttr("disabled");
+
+ });
+ </script>
+ </head>
+
+ <body><form action="main.php" method="post" id="callbackForm" class="general">
+ <fieldset>
+ <strong><a href="#fillWithSamples" style="color:#000000;">fill with samples &raquo;</a></strong>
+ <table border="0" cellspacing="5" cellpadding="0">
+ <tbody>
+ <tr>
+ <td>Sex:</td>
+ <td><input class="radio" name="Sex" type="radio" value="male" />Male
+
+ <input class="radio" name="Sex" type="radio" value="female" />Female</td>
+ </tr>
+ <tr>
+ <td>Firstname:</td>
+ <td><input class="text" name="Firstname" type="text" /></td>
+ </tr>
+ <tr>
+ <td>Lastname:</td>
+ <td><input class="text" name="Lastname" type="text" /></td>
+ </tr>
+ <tr>
+ <td>E-Mail:</td>
+ <td><input class="text" name="Email" type="text" /></td>
+ </tr>
+ <tr>
+ <td>What would you like to eat?</td>
+ <td><input class="checkbox" name="Food[]" type="checkbox" value="pizza" />Pizza
+
+ <input class="checkbox" name="Food[]" type="checkbox" value="hamburger" />Hamburger
+
+ <input class="checkbox" name="Food[]" type="checkbox" value="salad" />Salad
+
+ <input class="checkbox" name="Food[]" type="checkbox" value="steak" />Steak</td>
+ </tr>
+ <tr>
+ <td>Age:</td>
+ <td><select name="age"> <option value="under 18">under 18</option> <option value="over 18">over 18</option> <option value="over 30">over 30</option> </select></td>
+ </tr>
+ <tr valign="top">
+ <td valign="top">I like (you can select more than one):</td>
+ <td><select name="likes[]" size="5" multiple="multiple"> <option value="Michael Jackson">Michael Jackson</option> <option value="rainy wheater">rainy wheater</option> <option value="a hot summer">a hot summer</option> <option value="small cats">small cats</option> <option value="funny movies">funny movies</option> <option value="I like everything">I like everything</option> </select></td>
+ </tr>
+ <tr>
+ <td></td>
+ <td><input title="Submit" alt="Submit" name="submitButton" type="submit" value="Submit" class="submit" id="submitButton" /> <input title="Reset" alt="Reset" name="reset" type="reset" value="Reset" /></td>
+ </tr>
+ </tbody>
+ </table>
+ </fieldset>
+ </form>
+ </body>
+</html>
BIN  examples/example2/loading.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 examples/example2/main.php
@@ -0,0 +1,49 @@
+<?php
+session_start();
+require_once("../../jCryption-1.1.php");
+
+$keyLength = 256;
+$jCryption = new jCryption();
+
+if(isset($_GET["generateKeypair"])) {
+ $keys = $jCryption->generateKeypair($keyLength);
+ $_SESSION["e"] = array("int" => $keys["e"], "hex" => $jCryption->dec2string($keys["e"],16));
+ $_SESSION["d"] = array("int" => $keys["d"], "hex" => $jCryption->dec2string($keys["d"],16));
+ $_SESSION["n"] = array("int" => $keys["n"], "hex" => $jCryption->dec2string($keys["n"],16));
+
+ echo '{"e":"'.$_SESSION["e"]["hex"].'","n":"'.$_SESSION["n"]["hex"].'","maxdigits":"'.intval($keyLength*2/16+3).'"}';
+} else {
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>Result</title>
+<style type="text/css">
+html,body {
+ margin:0;
+ padding:0;
+ font-family:Tahoma;
+ font-size:12px;
+}
+</style>
+</head>
+<body>
+
+<p><strong>orignial POST:</strong> <br/><?php print_r($_POST); ?></p>
+<?php
+$var = $jCryption->decrypt($_POST['jCryption'], $_SESSION["d"]["int"], $_SESSION["n"]["int"]);
+unset($_SESSION["e"]);
+unset($_SESSION["d"]);
+unset($_SESSION["n"]);
+parse_str($var,$result);
+?>
+
+<p><strong>decrypted POST:</strong> <br/><?php print_r($result); ?></p>
+
+</body>
+</html>
+
+<?php
+}
+?>
17 examples/string/encrypt.php
@@ -0,0 +1,17 @@
+<?php
+ session_start();
+ require_once("../../jCryption-1.1.php");
+ $keyLength = 256;
+ $jCryption = new jCryption();
+ if(isset($_GET["generateKeypair"])) {
+ $keys = $jCryption->generateKeypair($keyLength);
+ $_SESSION["e"] = array("int" => $keys["e"], "hex" => $jCryption->dec2string($keys["e"],16));
+ $_SESSION["d"] = array("int" => $keys["d"], "hex" => $jCryption->dec2string($keys["d"],16));
+ $_SESSION["n"] = array("int" => $keys["n"], "hex" => $jCryption->dec2string($keys["n"],16));
+
+ echo '{"e":"'.$_SESSION["e"]["hex"].'","n":"'.$_SESSION["n"]["hex"].'","maxdigits":"'.intval($keyLength*2/16+3).'"}';
+ } else {
+ $var = $jCryption->decrypt($_POST['jCryption'], $_SESSION["d"]["int"], $_SESSION["n"]["int"]);
+ echo $var;
+ }
+?>
61 examples/string/index.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Example 1</title>
+ <style type="text/css">
+ html,body {
+ margin:0;
+ padding:0;
+ font-family:Tahoma;
+ font-size:12px;
+ }
+ input,textarea,select {
+ font-family:Tahoma;
+ font-size:12px;
+ }
+ </style>
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
+ <script type="text/javascript" src="../../jquery.jcryption-1.1.min.js"></script>
+ <script type="text/javascript">
+ var $loader = $('<img src="loading.gif" alt="Loading..." title="Loading..." style="margin-right:15px;" />');
+ $(function() {
+
+ var keys;
+ $.jCryption.getKeys("encrypt.php?generateKeypair=true",function(receivedKeys) {
+ keys = receivedKeys;
+ $("#toEncrypt").attr("disabled",false);
+ $("#encrypt").attr("disabled",false);
+ $("#status").html('<span style="font-size: 16px;">Ready to encrypt</span>');
+ });
+
+ $("#encrypt").click(function() {
+ $.jCryption.encrypt($("#toEncrypt").val(),keys,function(encrypted) {
+ $("#toDecrypt").val(encrypted);
+ });
+ });
+
+ $("#decrypt").click(function() {
+ $("#result").html($loader);
+ $.ajax({
+ type: 'POST',
+ url: "encrypt.php",
+ data: {jCryption:$("#toDecrypt").val()},
+ success: function(data) {
+ $("#result").html(data);
+ }
+ });
+ });
+
+ });
+ </script>
+ </head>
+
+ <body>
+ <p id="status"><span style="font-size: 16px;">Waiting for Keys</span> <img src="loading.gif" alt="Loading..." title="Loading..." style="margin-right:15px;" /></p>
+ String: <input type="text" id="toEncrypt" disabled="disabled" /> <button id="encrypt" disabled="disabled">Encrypt</button><br/>
+ Encrypted String:<br/>
+ <textarea cols="40" rows="5" id="toDecrypt"></textarea><br/><button id="decrypt">Decrypt</button><br/><br/>
+ Decrypted:<p id="result"></p>
+ </body>
+</html>
BIN  examples/string/loading.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
705 jCryption-1.1.php
@@ -0,0 +1,705 @@
+<?php
+/**
+ * jCryption
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * Many of the functions in this class are from the PEAR Crypt_RSA package ...
+ * So most of the credits goes to the original creator of this package Alexander Valyalkin
+ * you can get the package under http://pear.php.net/package/Crypt_RSA
+ *
+ * I just changed, added, removed and improved some functions to fit the needs of jCryption
+ *
+ * @author Daniel Griesser <daniel.griesser@jcryption.org>
+ * @copyright 2009 Daniel Griesser
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version 1.0.1
+ * @link http://jcryption.org/
+ */
+class jCryption {
+
+ var $_key_len;
+ var $_e;
+
+ /**
+ * Constructor
+ *
+ * @access public
+ */
+ function jCryption($e = "\x01\x00\x01") {
+ $this->_e = $e;
+ }
+
+ /**
+ * Generates the Keypair with the given keyLength the encryption key e ist set staticlly
+ * set to 65537 for faster encryption.
+ *
+ * @param int $keyLength
+ * @return array
+ * @access public
+ */
+ function generateKeypair($keyLength) {
+ $this->_key_len = intval($keyLength);
+ if ($this->_key_len < 8) {
+ $this->_key_len = 8;
+ }
+
+ // set [e] to 0x10001 (65537)
+ $e = $this->bin2int($this->_e);
+
+ // generate [p], [q] and [n]
+ $p_len = intval(($this->_key_len + 1) / 2);
+ $q_len = $this->_key_len - $p_len;
+ $p1 = $q1 = 0;
+ do {
+ // generate prime number [$p] with length [$p_len] with the following condition:
+ // GCD($e, $p - 1) = 1
+
+ do {
+ $p = $this->getPrime($p_len);
+ $p1 = $this->dec($p);
+ $tmp = $this->GCD($e, $p1);
+ } while (!$this->isOne($tmp));
+ // generate prime number [$q] with length [$q_len] with the following conditions:
+ // GCD($e, $q - 1) = 1
+ // $q != $p
+
+ do {
+ $q = $this->getPrime($q_len);
+ //$q = 102238965184417281201422828818276460200050705922822343263269460146519295919831;
+ $q1 = $this->dec($q);
+ $tmp = $this->GCD($e, $q1);
+ } while (!$this->isOne($tmp) && !$this->cmpAbs($q, $p));
+
+ // if (p < q), then exchange them
+ if ($this->cmpAbs($p, $q) < 0) {
+ $tmp = $p;
+ $p = $q;
+ $q = $tmp;
+ $tmp = $p1;
+ $p1 = $q1;
+ $q1 = $tmp;
+ }
+ // calculate n = p * q
+ $n = $this->mul($p, $q);
+
+ } while ($this->bitLen($n) != $this->_key_len);
+
+ // calculate d = 1/e mod (p - 1) * (q - 1)
+ $pq = $this->mul($p1, $q1);
+ $d = $this->invmod($e, $pq);
+
+ // store RSA keypair attributes
+ $keypair = array('n'=>$n, 'e'=>$e, 'd'=>$d, 'p'=>$p, 'q'=>$q);
+
+ return $keypair;
+ }
+
+ function useKeys($keys,$keyLength) {
+ $this->_key_len = intval($keyLength);
+ if ($this->_key_len < 8) {
+ $this->_key_len = 8;
+ }
+
+ // set [e] to 0x10001 (65537)
+ $e = $this->bin2int($this->_e);
+
+ // generate [p], [q] and [n]
+ $p_len = intval(($this->_key_len + 1) / 2);
+ $q_len = $this->_key_len - $p_len;
+ $p1 = $q1 = 0;
+ do {
+ do {
+ $q = $keys[rand(0,count($keys))];
+ $p = $keys[rand(0,count($keys))];
+ $p1 = $this->dec($p);
+ $q1 = $this->dec($q);
+ } while (!$this->cmpAbs($q, $p));
+
+
+ // if (p < q), then exchange them
+ if ($this->cmpAbs($p, $q) < 0) {
+ $tmp = $p;
+ $p = $q;
+ $q = $tmp;
+ $tmp = $p1;
+ $p1 = $q1;
+ $q1 = $tmp;
+ }
+ // calculate n = p * q
+ $n = $this->mul($p, $q);
+
+ } while ($this->bitLen($n) != $this->_key_len);
+
+ // calculate d = 1/e mod (p - 1) * (q - 1)
+ $pq = $this->mul($p1, $q1);
+ $d = $this->invmod($e, $pq);
+
+ // store RSA keypair attributes
+ $keypair = array('n'=>$n, 'e'=>$e, 'd'=>$d, 'p'=>$p, 'q'=>$q);
+
+ return $keypair;
+ }
+
+ /**
+ * Finds greatest common divider (GCD) of $num1 and $num2
+ *
+ * @param string $num1
+ * @param string $num2
+ * @return string
+ * @access public
+ */
+ function GCD($num1, $num2) {
+ do {
+ $tmp = bcmod($num1, $num2);
+ $num1 = $num2;
+ $num2 = $tmp;
+ } while (bccomp($num2, '0'));
+ return $num1;
+ }
+
+ /**
+ * Performs Miller-Rabin primality test for number $num
+ * with base $base. Returns true, if $num is strong pseudoprime
+ * by base $base. Else returns false.
+ *
+ * @param string $num
+ * @param string $base
+ * @return bool
+ * @access private
+ */
+ function _millerTest($num, $base) {
+ if (!bccomp($num, '1')) {
+ // 1 is not prime ;)
+ return false;
+ }
+ $tmp = bcsub($num, '1');
+
+ $zero_bits = 0;
+ while (!bccomp(bcmod($tmp, '2'), '0')) {
+ $zero_bits++;
+ $tmp = bcdiv($tmp, '2');
+ }
+
+ $tmp = $this->powmod($base, $tmp, $num);
+ if (!bccomp($tmp, '1')) {
+ // $num is probably prime
+ return true;
+ }
+
+ while ($zero_bits--) {
+ if (!bccomp(bcadd($tmp, '1'), $num)) {
+ // $num is probably prime
+ return true;
+ }
+ $tmp = $this->powmod($tmp, '2', $num);
+ }
+ // $num is composite
+ return false;
+ }
+
+ /**
+ * Transforms binary representation of large integer into its native form.
+ *
+ * Example of transformation:
+ * $str = "\x12\x34\x56\x78\x90";
+ * $num = 0x9078563412;
+ *
+ * @param string $str
+ * @return string
+ * @access public
+ */
+ function bin2int($str) {
+ $result = '0';
+ $n = strlen($str);
+ do {
+ $result = bcadd(bcmul($result, '256'), ord($str {--$n} ));
+ } while ($n > 0);
+ return $result;
+ }
+
+ /**
+ * Transforms large integer into binary representation.
+ *
+ * Example of transformation:
+ * $num = 0x9078563412;
+ * $str = "\x12\x34\x56\x78\x90";
+ *
+ * @param string $num
+ * @return string
+ * @access public
+ */
+ function int2bin($num) {
+ $result = '';
+ do {
+ $result .= chr(bcmod($num, '256'));
+ $num = bcdiv($num, '256');
+ } while (bccomp($num, '0'));
+ return $result;
+ }
+
+ /**
+ * Calculates pow($num, $pow) (mod $mod)
+ *
+ * @param string $num
+ * @param string $pow
+ * @param string $mod
+ * @return string
+ * @access public
+ */
+ function powmod($num, $pow, $mod) {
+ if (function_exists('bcpowmod')) {
+ // bcpowmod is only available under PHP5
+ return bcpowmod($num, $pow, $mod);
+ }
+
+ // emulate bcpowmod
+ $result = '1';
+ do {
+ if (!bccomp(bcmod($pow, '2'), '1')) {
+ $result = bcmod(bcmul($result, $num), $mod);
+ }
+ $num = bcmod(bcpow($num, '2'), $mod);
+ $pow = bcdiv($pow, '2');
+ } while (bccomp($pow, '0'));
+ return $result;
+ }
+
+ /**
+ * Calculates $num1 * $num2
+ *
+ * @param string $num1
+ * @param string $num2
+ * @return string
+ * @access public
+ */
+ function mul($num1, $num2) {
+ return bcmul($num1, $num2);
+ }
+
+ /**
+ * Calculates $num1 % $num2
+ *
+ * @param string $num1
+ * @param string $num2
+ * @return string
+ * @access public
+ */
+ function mod($num1, $num2) {
+ return bcmod($num1, $num2);
+ }
+
+ /**
+ * Compares abs($num1) to abs($num2).
+ * Returns:
+ * -1, if abs($num1) < abs($num2)
+ * 0, if abs($num1) == abs($num2)
+ * 1, if abs($num1) > abs($num2)
+ *
+ * @param string $num1
+ * @param string $num2
+ * @return int
+ * @access public
+ */
+ function cmpAbs($num1, $num2) {
+ return bccomp($num1, $num2);
+ }
+
+ /**
+ * Tests $num on primality. Returns true, if $num is strong pseudoprime.
+ * Else returns false.
+ *
+ * @param string $num
+ * @return bool
+ * @access private
+ */
+ function isPrime($num) {
+ static $primes = null;
+ static $primes_cnt = 0;
+ if (is_null($primes)) {
+ // generate all primes up to 10000
+ $primes = array();
+ for ($i = 0; $i < 10000; $i++) {
+ $primes[] = $i;
+ }
+ $primes[0] = $primes[1] = 0;
+ for ($i = 2; $i < 100; $i++) {
+ while (!$primes[$i]) {
+ $i++;
+ }
+ $j = $i;
+ for ($j += $i; $j < 10000; $j += $i) {
+ $primes[$j] = 0;
+ }
+ }
+ $j = 0;
+ for ($i = 0; $i < 10000; $i++) {
+ if ($primes[$i]) {
+ $primes[$j++] = $primes[$i];
+ }
+ }
+ $primes_cnt = $j;
+ }
+
+ // try to divide number by small primes
+ for ($i = 0; $i < $primes_cnt; $i++) {
+ if (bccomp($num, $primes[$i]) <= 0) {
+ // number is prime
+ return true;
+ }
+ if (!bccomp(bcmod($num, $primes[$i]), '0')) {
+ // number divides by $primes[$i]
+ return false;
+ }
+ }
+
+ /*
+ try Miller-Rabin's probable-primality test for first
+ 7 primes as bases
+ */
+ for ($i = 0; $i < 7; $i++) {
+ if (!$this->_millerTest($num, $primes[$i])) {
+ // $num is composite
+ return false;
+ }
+ }
+ // $num is strong pseudoprime
+ return true;
+ }
+
+ /**
+ * Produces a better random number
+ * for seeding mt_rand()
+ *
+ * @access private
+ */
+ function _makeSeed() {
+ return hexdec(sha1(sha1(microtime()*mt_rand()).md5(microtime()*mt_rand())));
+ }
+
+ /**
+ * Generates prime number with length $bits_cnt
+ *
+ * @param int $bits_cnt
+ * @access public
+ */
+ function getPrime($bits_cnt) {
+ $bytes_n = intval($bits_cnt / 8);
+ $bits_n = $bits_cnt % 8;
+ do {
+ $str = '';
+ mt_srand($this->_makeSeed());
+ for ($i = 0; $i < $bytes_n; $i++) {
+ $str .= chr(sha1(mt_rand() * microtime()) & 0xff);
+ }
+ $n = mt_rand() * microtime() & 0xff;
+
+ $n |= 0x80;
+ $n >>= 8 - $bits_n;
+ $str .= chr($n);
+ $num = $this->bin2int($str);
+
+ // search for the next closest prime number after [$num]
+ if (!bccomp(bcmod($num, '2'), '0')) {
+ $num = bcadd($num, '1');
+ }
+ while (!$this->isPrime($num)) {
+ $num = bcadd($num, '2');
+ }
+
+ } while ($this->bitLen($num) != $bits_cnt);
+ return $num;
+ }
+
+ /**
+ * Calculates $num - 1
+ *
+ * @param string $num
+ * @return string
+ * @access public
+ */
+ function dec($num) {
+ return bcsub($num, '1');
+ }
+
+ /**
+ * Returns true, if $num is equal to one. Else returns false
+ *
+ * @param string $num
+ * @return bool
+ * @access public
+ */
+ function isOne($num) {
+ return !bccomp($num, '1');
+ }
+
+ /**
+ * Finds inverse number $inv for $num by modulus $mod, such as:
+ * $inv * $num = 1 (mod $mod)
+ *
+ * @param string $num
+ * @param string $mod
+ * @return string
+ * @access public
+ */
+ function invmod($num, $mod) {
+ $x = '1';
+ $y = '0';
+ $num1 = $mod;
+ do {
+ $tmp = bcmod($num, $num1);
+ $q = bcdiv($num, $num1);
+ $num = $num1;
+ $num1 = $tmp;
+
+ $tmp = bcsub($x, bcmul($y, $q));
+ $x = $y;
+ $y = $tmp;
+ } while (bccomp($num1, '0'));
+ if (bccomp($x, '0') < 0) {
+ $x = bcadd($x, $mod);
+ }
+ return $x;
+ }
+
+ /**
+ * Returns bit length of number $num
+ *
+ * @param string $num
+ * @return int
+ * @access public
+ */
+ function bitLen($num) {
+ $tmp = $this->int2bin($num);
+ $bit_len = strlen($tmp) * 8;
+ $tmp = ord($tmp {strlen($tmp) - 1} );
+ if (!$tmp) {
+ $bit_len -= 8;
+ } else {
+ while (!($tmp & 0x80)) {
+ $bit_len--;
+ $tmp <<= 1;
+ }
+ }
+ return $bit_len;
+ }
+
+ /**
+ * Calculates bitwise or of $num1 and $num2,
+ * starting from bit $start_pos for number $num1
+ *
+ * @param string $num1
+ * @param string $num2
+ * @param int $start_pos
+ * @return string
+ * @access public
+ */
+ function bitOr($num1, $num2, $start_pos) {
+ $start_byte = intval($start_pos / 8);
+ $start_bit = $start_pos % 8;
+ $tmp1 = $this->int2bin($num1);
+
+ $num2 = bcmul($num2, 1 << $start_bit);
+ $tmp2 = $this->int2bin($num2);
+ if ($start_byte < strlen($tmp1)) {
+ $tmp2 |= substr($tmp1, $start_byte);
+ $tmp1 = substr($tmp1, 0, $start_byte).$tmp2;
+ } else {
+ $tmp1 = str_pad($tmp1, $start_byte, "\0").$tmp2;
+ }
+ return $this->bin2int($tmp1);
+ }
+
+ /**
+ * Returns part of number $num, starting at bit
+ * position $start with length $length
+ *
+ * @param string $num
+ * @param int start
+ * @param int length
+ * @return string
+ * @access public
+ */
+ function subint($num, $start, $length) {
+ $start_byte = intval($start / 8);
+ $start_bit = $start % 8;
+ $byte_length = intval($length / 8);
+ $bit_length = $length % 8;
+ if ($bit_length) {
+ $byte_length++;
+ }
+ $num = bcdiv($num, 1 << $start_bit);
+ $tmp = substr($this->int2bin($num), $start_byte, $byte_length);
+ $tmp = str_pad($tmp, $byte_length, "\0");
+ $tmp = substr_replace($tmp, $tmp {$byte_length - 1} & chr(0xff >> (8 - $bit_length)), $byte_length - 1, 1);
+ return $this->bin2int($tmp);
+ }
+
+ /**
+ * Converts a hex string to bigint string
+ *
+ * @param string $hex
+ * @return string
+ * @access public
+ */
+ function hex2bint($hex) {
+ $result = '0';
+ for ($i = 0; $i < strlen($hex); $i++) {
+ $result = bcmul($result, '16');
+ if ($hex[$i] >= '0' && $hex[$i] <= '9') {
+ $result = bcadd($result, $hex[$i]);
+ } else if ($hex[$i] >= 'a' && $hex[$i] <= 'f') {
+ $result = bcadd($result, '1'.('0' + (ord($hex[$i]) - ord('a'))));
+ } else if ($hex[$i] >= 'A' && $hex[$i] <= 'F') {
+ $result = bcadd($result, '1'.('0' + (ord($hex[$i]) - ord('A'))));
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Converts a hex string to int
+ *
+ * @param string $hex
+ * @return int
+ * @access public
+ */
+ function hex2int($hex) {
+ $result = 0;
+ for ($i = 0; $i < strlen($hex); $i++) {
+ $result *= 16;
+ if ($hex[$i] >= '0' && $hex[$i] <= '9') {
+ $result += ord($hex[$i]) - ord('0');
+ } else if ($hex[$i] >= 'a' && $hex[$i] <= 'f') {
+ $result += 10 + (ord($hex[$i]) - ord('a'));
+ } else if ($hex[$i] >= 'A' && $hex[$i] <= 'F') {
+ $result += 10 + (ord($hex[$i]) - ord('A'));
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Converts a bigint string to the ascii code
+ *
+ * @param string $bigint
+ * @return string
+ * @access public
+ */
+ function bint2char($bigint) {
+ $message = '';
+ while (bccomp($bigint, '0') != 0) {
+ $ascii = bcmod($bigint, '256');
+ $bigint = bcdiv($bigint, '256', 0);
+ $message .= chr($ascii);
+ }
+ return $message;
+ }
+
+ /**
+ * Removes the redundacy in den encrypted string
+ *
+ * @param string $string
+ * @return mixed
+ * @access public
+ */
+ function redundacyCheck($string) {
+ $r1 = substr($string, 0, 2);
+ $r2 = substr($string, 2);
+ $check = $this->hex2int($r1);
+ $value = $r2;
+ $sum = 0;
+ for ($i = 0; $i < strlen($value); $i++) {
+ $sum += ord($value[$i]);
+ }
+ if ($check == ($sum & 0xFF)) {
+ return $value;
+ } else {
+ return NULL;
+ }
+ }
+
+ /**
+ * Decrypts a given string with the $dec_key and the $enc_mod
+ *
+ * @param string $encrypted
+ * @param int $dec_key
+ * @param int $enc_mod
+ * @return string
+ * @access public
+ */
+ function decrypt($encrypted, $dec_key, $enc_mod) {
+ $blocks = split(' ', $encrypted);
+ $result = "";
+ $max = count($blocks);
+ for ($i = 0; $i < $max; $i++) {
+ $dec = $this->hex2bint($blocks[$i]);
+ $dec = $this->powmod($dec, $dec_key, $enc_mod);
+ $ascii = $this->bint2char($dec);
+ $result .= $ascii;
+ }
+ return $this->redundacyCheck($result);
+ }
+
+ /**
+ * Converts a given decimal string to any base between 2 and 36
+ *
+ * @param string $decimal
+ * @param int $base
+ * @return string
+ */
+ function dec2string($decimal, $base) {
+
+ $string = null;
+
+ $base = (int) $base;
+ if ($base < 2 | $base > 36 | $base == 10) {
+ echo 'BASE must be in the range 2-9 or 11-36';
+ exit;
+ }
+
+ $charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+
+ $charset = substr($charset, 0, $base);
+
+ do {
+ $remainder = bcmod($decimal, $base);
+ $char = substr($charset, $remainder, 1);
+ $string = "$char$string";
+ $decimal = bcdiv(bcsub($decimal, $remainder), $base);
+ } while ($decimal > 0);
+
+ return strtolower($string);
+ }
+
+ function getE() {
+ return $this->_e;
+ }
+
+ function generatePrime($length) {
+ $this->_key_len = intval($length);
+ if ($this->_key_len < 8) {
+ $this->_key_len = 8;
+ }
+
+ $e = $this->bin2int("\x01\x00\x01");
+
+ $p_len = intval(($this->_key_len + 1) / 2);
+ do {
+ $p = $this->getPrime($p_len);
+ $p1 = $this->dec($p);
+ $tmp = $this->GCD($e, $p1);
+ } while (!$this->isOne($tmp));
+
+ return $p;
+ }
+
+}
+
+?>
723 jquery.jcryption-1.1.js
@@ -0,0 +1,723 @@
+/*
+* jCryption JavaScript data encryption v1.1
+* http://www.jcryption.org/
+*
+* Copyright (c) 2010 Daniel Griesser
+* Dual licensed under the MIT and GPL licenses.
+* http://www.opensource.org/licenses/mit-license.php
+* http://www.opensource.org/licenses/gpl-2.0.php
+*
+* If you need any further information about this plugin please
+* visit my homepage or contact me under daniel.griesser@jcryption.org
+*/
+(function($) {
+ $.jCryption = function(el, options) {
+ var base = this;
+
+ base.$el = $(el);
+ base.el = el;
+
+ base.$el.data("jCryption", base);
+ base.init = function() {
+
+ base.options = $.extend({},$.jCryption.defaultOptions, options);
+
+ $encryptedElement = $("<input />",{
+ type:'hidden',
+ name:base.options.postVariable
+ });
+
+ if (base.options.submitElement !== false) {
+ var $submitElement = base.options.submitElement;
+ } else {
+ var $submitElement = base.$el.find(":input:submit");
+ }
+
+ $submitElement.bind(base.options.submitEvent,function() {
+ $(this).attr("disabled",true);
+ if(base.options.beforeEncryption()) {
+ $.jCryption.getKeys(base.options.getKeysURL,function(keys) {
+ $.jCryption.encrypt(base.$el.serialize(),keys,function(encrypted) {
+ $encryptedElement.val(encrypted);
+ $(base.$el).find(":input").attr("disabled",true).end().append($encryptedElement).submit();
+ });
+ });
+ }
+ return false;
+ });
+
+ };
+
+ base.init();
+ };
+
+ $.jCryption.getKeys = function(url,callback) {
+ var base = this;
+ base.getKeys = function() {
+ $.getJSON(url,function(data){
+ keys = new base.jCryptionKeyPair(data.e,data.n,data.maxdigits);
+ if($.isFunction(callback)) {
+ callback.call(this, keys);
+ }
+ });
+ };
+
+ base.jCryptionKeyPair = function(encryptionExponent, modulus, maxdigits) {
+ setMaxDigits(parseInt(maxdigits,10));
+ this.e = biFromHex(encryptionExponent);
+ this.m = biFromHex(modulus);
+ this.chunkSize = 2 * biHighIndex(this.m);
+ this.radix = 16;
+ this.barrett = new BarrettMu(this.m);
+ };
+
+ base.getKeys();
+ };
+
+ $.jCryption.encrypt = function(string,keyPair,callback) {
+ var charSum = 0;
+ for(var i = 0; i < string.length; i++){
+ charSum += string.charCodeAt(i);
+ }
+ var tag = '0123456789abcdef';
+ var hex = '';
+ hex += tag.charAt((charSum & 0xF0) >> 4) + tag.charAt(charSum & 0x0F);
+
+ var taggedString = hex + string;
+
+ var encrypt = [];
+ var j = 0;
+
+ while (j < taggedString.length) {
+ encrypt[j] = taggedString.charCodeAt(j);
+ j++;
+ }
+
+ while (encrypt.length % keyPair.chunkSize !== 0) {
+ encrypt[j++] = 0;
+ }
+
+ function encryption(encryptObject) {
+ var charCounter = 0;
+ var j, block;
+ var encrypted = "";
+ function encryptChar() {
+ block = new BigInt();
+ j = 0;
+ for (var k = charCounter; k < charCounter+keyPair.chunkSize; ++j) {
+ block.digits[j] = encryptObject[k++];
+ block.digits[j] += encryptObject[k++] << 8;
+ }
+ var crypt = keyPair.barrett.powMod(block, keyPair.e);
+ var text = keyPair.radix == 16 ? biToHex(crypt) : biToString(crypt, keyPair.radix);
+ encrypted += text + " ";
+ charCounter += keyPair.chunkSize;
+ if (charCounter < encryptObject.length) {
+ setTimeout(encryptChar, 1)
+ } else {
+ var encryptedString = encrypted.substring(0, encrypted.length - 1);
+ if($.isFunction(callback)) {
+ callback(encryptedString);
+ } else {
+ return encryptedString;
+ }
+
+ }
+ }
+ setTimeout(encryptChar, 1);
+ }
+
+ encryption(encrypt);
+ };
+
+ $.jCryption.defaultOptions = {
+ submitElement:false,
+ submitEvent:"click",
+ getKeysURL:"main.php?generateKeypair=true",
+ beforeEncryption:function(){return true},
+ postVariable:"jCryption"
+ };
+
+ $.fn.jCryption = function(options) {
+ return this.each(function(){
+ (new $.jCryption(this, options));
+ });
+ };
+
+})(jQuery);
+
+/*
+* BigInt, a suite of routines for performing multiple-precision arithmetic in
+* JavaScript.
+* BarrettMu, a class for performing Barrett modular reduction computations in
+* JavaScript.
+*
+*
+* Copyright 1998-2005 David Shapiro.
+* dave@ohdave.com
+*
+* changed and improved by Daniel Griesser
+* http://www.jcryption.org/
+* Daniel Griesser <daniel.griesser@jcryption.org>
+*/
+var biRadixBase = 2;
+var biRadixBits = 16;
+var bitsPerDigit = biRadixBits;
+var biRadix = 1 << 16;
+var biHalfRadix = biRadix >>> 1;
+var biRadixSquared = biRadix * biRadix;
+var maxDigitVal = biRadix - 1;
+var maxInteger = 9999999999999998;
+var maxDigits;
+var ZERO_ARRAY;
+var bigZero, bigOne;
+var dpl10 = 15;
+var highBitMasks = new Array(0x0000, 0x8000, 0xC000, 0xE000, 0xF000, 0xF800,
+0xFC00, 0xFE00, 0xFF00, 0xFF80, 0xFFC0, 0xFFE0,
+0xFFF0, 0xFFF8, 0xFFFC, 0xFFFE, 0xFFFF);
+
+var hexatrigesimalToChar = new Array(
+'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
+'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
+'u', 'v', 'w', 'x', 'y', 'z'
+);
+
+var hexToChar = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+'a', 'b', 'c', 'd', 'e', 'f');
+
+var lowBitMasks = new Array(0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F,
+0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF,
+0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF);
+
+function setMaxDigits(value) {
+ maxDigits = value;
+ ZERO_ARRAY = new Array(maxDigits);
+ for (var iza = 0; iza < ZERO_ARRAY.length; iza++) ZERO_ARRAY[iza] = 0;
+ bigZero = new BigInt();
+ bigOne = new BigInt();
+ bigOne.digits[0] = 1;
+}
+
+function BigInt(flag) {
+ if (typeof flag == "boolean" && flag == true) {
+ this.digits = null;
+ }
+ else {
+ this.digits = ZERO_ARRAY.slice(0);
+ }
+ this.isNeg = false;
+}
+
+function biFromDecimal(s) {
+ var isNeg = s.charAt(0) == '-';
+ var i = isNeg ? 1 : 0;
+ var result;
+ while (i < s.length && s.charAt(i) == '0') ++i;
+ if (i == s.length) {
+ result = new BigInt();
+ }
+ else {
+ var digitCount = s.length - i;
+ var fgl = digitCount % dpl10;
+ if (fgl == 0) fgl = dpl10;
+ result = biFromNumber(Number(s.substr(i, fgl)));
+ i += fgl;
+ while (i < s.length) {
+ result = biAdd(biMultiply(result, biFromNumber(1000000000000000)),
+ biFromNumber(Number(s.substr(i, dpl10))));
+ i += dpl10;
+ }
+ result.isNeg = isNeg;
+ }
+ return result;
+}
+
+function biCopy(bi) {
+ var result = new BigInt(true);
+ result.digits = bi.digits.slice(0);
+ result.isNeg = bi.isNeg;
+ return result;
+}
+
+function biFromNumber(i) {
+ var result = new BigInt();
+ result.isNeg = i < 0;
+ i = Math.abs(i);
+ var j = 0;
+ while (i > 0) {
+ result.digits[j++] = i & maxDigitVal;
+ i >>= biRadixBits;
+ }
+ return result;
+}
+
+function reverseStr(s) {
+ var result = "";
+ for (var i = s.length - 1; i > -1; --i) {
+ result += s.charAt(i);
+ }
+ return result;
+}
+
+function biToString(x, radix) {
+ var b = new BigInt();
+ b.digits[0] = radix;
+ var qr = biDivideModulo(x, b);
+ var result = hexatrigesimalToChar[qr[1].digits[0]];
+ while (biCompare(qr[0], bigZero) == 1) {
+ qr = biDivideModulo(qr[0], b);
+ digit = qr[1].digits[0];
+ result += hexatrigesimalToChar[qr[1].digits[0]];
+ }
+ return (x.isNeg ? "-" : "") + reverseStr(result);
+}
+
+function biToDecimal(x) {
+ var b = new BigInt();
+ b.digits[0] = 10;
+ var qr = biDivideModulo(x, b);
+ var result = String(qr[1].digits[0]);
+ while (biCompare(qr[0], bigZero) == 1) {
+ qr = biDivideModulo(qr[0], b);
+ result += String(qr[1].digits[0]);
+ }
+ return (x.isNeg ? "-" : "") + reverseStr(result);
+}
+
+function digitToHex(n) {
+ var mask = 0xf;
+ var result = "";
+ for (i = 0; i < 4; ++i) {
+ result += hexToChar[n & mask];
+ n >>>= 4;
+ }
+ return reverseStr(result);
+}
+
+function biToHex(x) {
+ var result = "";
+ var n = biHighIndex(x);
+ for (var i = biHighIndex(x); i > -1; --i) {
+ result += digitToHex(x.digits[i]);
+ }
+ return result;
+}
+
+function charToHex(c) {
+ var ZERO = 48;
+ var NINE = ZERO + 9;
+ var littleA = 97;
+ var littleZ = littleA + 25;
+ var bigA = 65;
+ var bigZ = 65 + 25;
+ var result;
+
+ if (c >= ZERO && c <= NINE) {
+ result = c - ZERO;
+ } else if (c >= bigA && c <= bigZ) {
+ result = 10 + c - bigA;
+ } else if (c >= littleA && c <= littleZ) {
+ result = 10 + c - littleA;
+ } else {
+ result = 0;
+ }
+ return result;
+}
+
+function hexToDigit(s) {
+ var result = 0;
+ var sl = Math.min(s.length, 4);
+ for (var i = 0; i < sl; ++i) {
+ result <<= 4;
+ result |= charToHex(s.charCodeAt(i))
+ }
+ return result;
+}
+
+function biFromHex(s) {
+ var result = new BigInt();
+ var sl = s.length;
+ for (var i = sl, j = 0; i > 0; i -= 4, ++j) {
+ result.digits[j] = hexToDigit(s.substr(Math.max(i - 4, 0), Math.min(i, 4)));
+ }
+ return result;
+}
+
+function biFromString(s, radix) {
+ var isNeg = s.charAt(0) == '-';
+ var istop = isNeg ? 1 : 0;
+ var result = new BigInt();
+ var place = new BigInt();
+ place.digits[0] = 1; // radix^0
+ for (var i = s.length - 1; i >= istop; i--) {
+ var c = s.charCodeAt(i);
+ var digit = charToHex(c);
+ var biDigit = biMultiplyDigit(place, digit);
+ result = biAdd(result, biDigit);
+ place = biMultiplyDigit(place, radix);
+ }
+ result.isNeg = isNeg;
+ return result;
+}
+
+function biDump(b) {
+ return (b.isNeg ? "-" : "") + b.digits.join(" ");
+}
+
+function biAdd(x, y) {
+ var result;
+
+ if (x.isNeg != y.isNeg) {
+ y.isNeg = !y.isNeg;
+ result = biSubtract(x, y);
+ y.isNeg = !y.isNeg;
+ }
+ else {
+ result = new BigInt();
+ var c = 0;
+ var n;
+ for (var i = 0; i < x.digits.length; ++i) {
+ n = x.digits[i] + y.digits[i] + c;
+ result.digits[i] = n & 0xffff;
+ c = Number(n >= biRadix);
+ }
+ result.isNeg = x.isNeg;
+ }
+ return result;
+}
+
+function biSubtract(x, y) {
+ var result;
+ if (x.isNeg != y.isNeg) {
+ y.isNeg = !y.isNeg;
+ result = biAdd(x, y);
+ y.isNeg = !y.isNeg;
+ } else {
+ result = new BigInt();
+ var n, c;
+ c = 0;
+ for (var i = 0; i < x.digits.length; ++i) {
+ n = x.digits[i] - y.digits[i] + c;
+ result.digits[i] = n & 0xffff;
+ if (result.digits[i] < 0) result.digits[i] += biRadix;
+ c = 0 - Number(n < 0);
+ }
+ if (c == -1) {
+ c = 0;
+ for (var i = 0; i < x.digits.length; ++i) {
+ n = 0 - result.digits[i] + c;
+ result.digits[i] = n & 0xffff;
+ if (result.digits[i] < 0) result.digits[i] += biRadix;
+ c = 0 - Number(n < 0);
+ }
+ result.isNeg = !x.isNeg;
+ } else {
+ result.isNeg = x.isNeg;
+ }
+ }
+ return result;
+}
+
+function biHighIndex(x) {
+ var result = x.digits.length - 1;
+ while (result > 0 && x.digits[result] == 0) --result;
+ return result;
+}
+
+function biNumBits(x) {
+ var n = biHighIndex(x);
+ var d = x.digits[n];
+ var m = (n + 1) * bitsPerDigit;
+ var result;
+ for (result = m; result > m - bitsPerDigit; --result) {
+ if ((d & 0x8000) != 0) break;
+ d <<= 1;
+ }
+ return result;
+}
+
+function biMultiply(x, y) {
+ var result = new BigInt();
+ var c;
+ var n = biHighIndex(x);
+ var t = biHighIndex(y);
+ var u, uv, k;
+
+ for (var i = 0; i <= t; ++i) {
+ c = 0;
+ k = i;
+ for (j = 0; j <= n; ++j, ++k) {
+ uv = result.digits[k] + x.digits[j] * y.digits[i] + c;
+ result.digits[k] = uv & maxDigitVal;
+ c = uv >>> biRadixBits;
+ }
+ result.digits[i + n + 1] = c;
+ }
+ result.isNeg = x.isNeg != y.isNeg;
+ return result;
+}
+
+function biMultiplyDigit(x, y) {
+ var n, c, uv;
+
+ result = new BigInt();
+ n = biHighIndex(x);
+ c = 0;
+ for (var j = 0; j <= n; ++j) {
+ uv = result.digits[j] + x.digits[j] * y + c;
+ result.digits[j] = uv & maxDigitVal;
+ c = uv >>> biRadixBits;
+ }
+ result.digits[1 + n] = c;
+ return result;
+}
+
+function arrayCopy(src, srcStart, dest, destStart, n) {
+ var m = Math.min(srcStart + n, src.length);
+ for (var i = srcStart, j = destStart; i < m; ++i, ++j) {
+ dest[j] = src[i];
+ }
+}
+
+
+
+function biShiftLeft(x, n) {
+ var digitCount = Math.floor(n / bitsPerDigit);
+ var result = new BigInt();
+ arrayCopy(x.digits, 0, result.digits, digitCount,result.digits.length - digitCount);
+ var bits = n % bitsPerDigit;
+ var rightBits = bitsPerDigit - bits;
+ for (var i = result.digits.length - 1, i1 = i - 1; i > 0; --i, --i1) {
+ result.digits[i] = ((result.digits[i] << bits) & maxDigitVal) |
+ ((result.digits[i1] & highBitMasks[bits]) >>>
+ (rightBits));
+ }
+ result.digits[0] = ((result.digits[i] << bits) & maxDigitVal);
+ result.isNeg = x.isNeg;
+ return result;
+}
+
+function biShiftRight(x, n) {
+ var digitCount = Math.floor(n / bitsPerDigit);
+ var result = new BigInt();
+ arrayCopy(x.digits, digitCount, result.digits, 0,x.digits.length - digitCount);
+ var bits = n % bitsPerDigit;
+ var leftBits = bitsPerDigit - bits;
+ for (var i = 0, i1 = i + 1; i < result.digits.length - 1; ++i, ++i1) {
+ result.digits[i] = (result.digits[i] >>> bits) |
+ ((result.digits[i1] & lowBitMasks[bits]) << leftBits);
+ }
+ result.digits[result.digits.length - 1] >>>= bits;
+ result.isNeg = x.isNeg;
+ return result;
+}
+
+function biMultiplyByRadixPower(x, n) {
+ var result = new BigInt();
+ arrayCopy(x.digits, 0, result.digits, n, result.digits.length - n);
+ return result;
+}
+
+function biDivideByRadixPower(x, n)
+{
+ var result = new BigInt();
+ arrayCopy(x.digits, n, result.digits, 0, result.digits.length - n);
+ return result;
+}
+
+function biModuloByRadixPower(x, n)
+{
+ var result = new BigInt();
+ arrayCopy(x.digits, 0, result.digits, 0, n);
+ return result;
+}
+
+function biCompare(x, y) {
+ if (x.isNeg != y.isNeg) {
+ return 1 - 2 * Number(x.isNeg);
+ }
+ for (var i = x.digits.length - 1; i >= 0; --i) {
+ if (x.digits[i] != y.digits[i]) {
+ if (x.isNeg) {
+ return 1 - 2 * Number(x.digits[i] > y.digits[i]);
+ } else {
+ return 1 - 2 * Number(x.digits[i] < y.digits[i]);
+ }
+ }
+ }
+ return 0;
+}
+
+function biDivideModulo(x, y) {
+ var nb = biNumBits(x);
+ var tb = biNumBits(y);
+ var origYIsNeg = y.isNeg;
+ var q, r;
+ if (nb < tb) {
+ if (x.isNeg) {
+ q = biCopy(bigOne);
+ q.isNeg = !y.isNeg;
+ x.isNeg = false;
+ y.isNeg = false;
+ r = biSubtract(y, x);
+ x.isNeg = true;
+ y.isNeg = origYIsNeg;
+ } else {
+ q = new BigInt();
+ r = biCopy(x);
+ }
+ return new Array(q, r);
+ }
+
+ q = new BigInt();
+ r = x;
+
+ var t = Math.ceil(tb / bitsPerDigit) - 1;
+ var lambda = 0;
+ while (y.digits[t] < biHalfRadix) {
+ y = biShiftLeft(y, 1);
+ ++lambda;
+ ++tb;
+ t = Math.ceil(tb / bitsPerDigit) - 1;
+ }
+
+ r = biShiftLeft(r, lambda);
+ nb += lambda;
+ var n = Math.ceil(nb / bitsPerDigit) - 1;
+
+ var b = biMultiplyByRadixPower(y, n - t);
+ while (biCompare(r, b) != -1) {
+ ++q.digits[n - t];
+ r = biSubtract(r, b);
+ }
+ for (var i = n; i > t; --i) {
+ var ri = (i >= r.digits.length) ? 0 : r.digits[i];
+ var ri1 = (i - 1 >= r.digits.length) ? 0 : r.digits[i - 1];
+ var ri2 = (i - 2 >= r.digits.length) ? 0 : r.digits[i - 2];
+ var yt = (t >= y.digits.length) ? 0 : y.digits[t];
+ var yt1 = (t - 1 >= y.digits.length) ? 0 : y.digits[t - 1];
+ if (ri == yt) {
+ q.digits[i - t - 1] = maxDigitVal;
+ } else {
+ q.digits[i - t - 1] = Math.floor((ri * biRadix + ri1) / yt);
+ }
+
+ var c1 = q.digits[i - t - 1] * ((yt * biRadix) + yt1);
+ var c2 = (ri * biRadixSquared) + ((ri1 * biRadix) + ri2);
+ while (c1 > c2) {
+ --q.digits[i - t - 1];
+ c1 = q.digits[i - t - 1] * ((yt * biRadix) | yt1);
+ c2 = (ri * biRadix * biRadix) + ((ri1 * biRadix) + ri2);
+ }
+
+ b = biMultiplyByRadixPower(y, i - t - 1);
+ r = biSubtract(r, biMultiplyDigit(b, q.digits[i - t - 1]));
+ if (r.isNeg) {
+ r = biAdd(r, b);
+ --q.digits[i - t - 1];
+ }
+ }
+ r = biShiftRight(r, lambda);
+
+ q.isNeg = x.isNeg != origYIsNeg;
+ if (x.isNeg) {
+ if (origYIsNeg) {
+ q = biAdd(q, bigOne);
+ } else {
+ q = biSubtract(q, bigOne);
+ }
+ y = biShiftRight(y, lambda);
+ r = biSubtract(y, r);
+ }
+
+ if (r.digits[0] == 0 && biHighIndex(r) == 0) r.isNeg = false;
+
+ return new Array(q, r);
+}
+
+function biDivide(x, y) {
+ return biDivideModulo(x, y)[0];
+}
+
+function biModulo(x, y) {
+ return biDivideModulo(x, y)[1];
+}
+
+function biMultiplyMod(x, y, m) {
+ return biModulo(biMultiply(x, y), m);
+}
+
+function biPow(x, y) {
+ var result = bigOne;
+ var a = x;
+ while (true) {
+ if ((y & 1) != 0) result = biMultiply(result, a);
+ y >>= 1;
+ if (y == 0) break;
+ a = biMultiply(a, a);
+ }
+ return result;
+}
+
+function biPowMod(x, y, m) {
+ var result = bigOne;
+ var a = x;
+ var k = y;
+ while (true) {
+ if ((k.digits[0] & 1) != 0) result = biMultiplyMod(result, a, m);
+ k = biShiftRight(k, 1);
+ if (k.digits[0] == 0 && biHighIndex(k) == 0) break;
+ a = biMultiplyMod(a, a, m);
+ }
+ return result;
+}
+
+function BarrettMu(m) {
+ this.modulus = biCopy(m);
+ this.k = biHighIndex(this.modulus) + 1;
+ var b2k = new BigInt();
+ b2k.digits[2 * this.k] = 1;
+ this.mu = biDivide(b2k, this.modulus);
+ this.bkplus1 = new BigInt();
+ this.bkplus1.digits[this.k + 1] = 1;
+ this.modulo = BarrettMu_modulo;
+ this.multiplyMod = BarrettMu_multiplyMod;
+ this.powMod = BarrettMu_powMod;
+}
+
+function BarrettMu_modulo(x) {
+ var q1 = biDivideByRadixPower(x, this.k - 1);
+ var q2 = biMultiply(q1, this.mu);
+ var q3 = biDivideByRadixPower(q2, this.k + 1);
+ var r1 = biModuloByRadixPower(x, this.k + 1);
+ var r2term = biMultiply(q3, this.modulus);
+ var r2 = biModuloByRadixPower(r2term, this.k + 1);
+ var r = biSubtract(r1, r2);
+ if (r.isNeg) {
+ r = biAdd(r, this.bkplus1);
+ }
+ var rgtem = biCompare(r, this.modulus) >= 0;
+ while (rgtem) {
+ r = biSubtract(r, this.modulus);
+ rgtem = biCompare(r, this.modulus) >= 0;
+ }
+ return r;
+}
+
+function BarrettMu_multiplyMod(x, y) {
+ var xy = biMultiply(x, y);
+ return this.modulo(xy);
+}
+
+function BarrettMu_powMod(x, y) {
+ var result = new BigInt();
+ result.digits[0] = 1;
+ while (true) {
+ if ((y.digits[0] & 1) != 0) result = this.multiplyMod(result, x);
+ y = biShiftRight(y, 1);
+ if (y.digits[0] == 0 && biHighIndex(y) == 0) break;
+ x = this.multiplyMod(x, x);
+ }
+ return result;
+}
25 jquery.jcryption-1.1.min.js
@@ -0,0 +1,25 @@
+(function(a){a.jCryption=function(b,c){var d=this;d.$el=a(b);d.el=b;d.$el.data("jCryption",d);d.init=function(){d.options=a.extend({},a.jCryption.defaultOptions,c);$encryptedElement=a("<input />",{type:"hidden",name:d.options.postVariable});(d.options.submitElement!==false?d.options.submitElement:d.$el.find(":input:submit")).bind(d.options.submitEvent,function(){a(this).attr("disabled",true);d.options.beforeEncryption()&&a.jCryption.getKeys(d.options.getKeysURL,function(e){a.jCryption.encrypt(d.$el.serialize(),
+e,function(f){$encryptedElement.val(f);a(d.$el).find(":input").attr("disabled",true).end().append($encryptedElement).submit()})});return false})};d.init()};a.jCryption.getKeys=function(b,c){var d=this;d.getKeys=function(){a.getJSON(b,function(e){keys=new d.jCryptionKeyPair(e.e,e.n,e.maxdigits);a.isFunction(c)&&c.call(this,keys)})};d.jCryptionKeyPair=function(e,f,g){setMaxDigits(parseInt(g,10));this.e=biFromHex(e);this.m=biFromHex(f);this.chunkSize=2*biHighIndex(this.m);this.radix=16;this.barrett=
+new BarrettMu(this.m)};d.getKeys()};a.jCryption.encrypt=function(b,c,d){for(var e=0,f=0;f<b.length;f++)e+=b.charCodeAt(f);f="";f+="0123456789abcdef".charAt((e&240)>>4)+"0123456789abcdef".charAt(e&15);b=f+b;e=[];for(f=0;f<b.length;){e[f]=b.charCodeAt(f);f++}for(;e.length%c.chunkSize!==0;)e[f++]=0;(function(g){function h(){o=new BigInt;m=0;for(var k=l;k<l+c.chunkSize;++m){o.digits[m]=g[k++];o.digits[m]+=g[k++]<<8}k=c.barrett.powMod(o,c.e);k=c.radix==16?biToHex(k):biToString(k,c.radix);n+=k+" ";l+=c.chunkSize;
+if(l<g.length)setTimeout(h,1);else{k=n.substring(0,n.length-1);if(a.isFunction(d))d(k);else return k}}var l=0,m,o,n="";setTimeout(h,1)})(e)};a.jCryption.defaultOptions={submitElement:false,submitEvent:"click",getKeysURL:"main.php?generateKeypair=true",beforeEncryption:function(){return true},postVariable:"jCryption"};a.fn.jCryption=function(b){return this.each(function(){new a.jCryption(this,b)})}})(jQuery);
+var biRadixBase=2,biRadixBits=16,bitsPerDigit=biRadixBits,biRadix=65536,biHalfRadix=biRadix>>>1,biRadixSquared=biRadix*biRadix,maxDigitVal=biRadix-1,maxInteger=9999999999999998,maxDigits,ZERO_ARRAY,bigZero,bigOne,dpl10=15,highBitMasks=Array(0,32768,49152,57344,61440,63488,64512,65024,65280,65408,65472,65504,65520,65528,65532,65534,65535),hexatrigesimalToChar=Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x",
+"y","z"),hexToChar=Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"),lowBitMasks=Array(0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535);function setMaxDigits(a){maxDigits=a;ZERO_ARRAY=Array(maxDigits);for(a=0;a<ZERO_ARRAY.length;a++)ZERO_ARRAY[a]=0;bigZero=new BigInt;bigOne=new BigInt;bigOne.digits[0]=1}function BigInt(a){this.digits=typeof a=="boolean"&&a==true?null:ZERO_ARRAY.slice(0);this.isNeg=false}
+function biFromDecimal(a){for(var b=a.charAt(0)=="-",c=b?1:0,d;c<a.length&&a.charAt(c)=="0";)++c;if(c==a.length)d=new BigInt;else{var e=(a.length-c)%dpl10;if(e==0)e=dpl10;d=biFromNumber(Number(a.substr(c,e)));for(c+=e;c<a.length;){d=biAdd(biMultiply(d,biFromNumber(1E15)),biFromNumber(Number(a.substr(c,dpl10))));c+=dpl10}d.isNeg=b}return d}function biCopy(a){var b=new BigInt(true);b.digits=a.digits.slice(0);b.isNeg=a.isNeg;return b}
+function biFromNumber(a){var b=new BigInt;b.isNeg=a<0;a=Math.abs(a);for(var c=0;a>0;){b.digits[c++]=a&maxDigitVal;a>>=biRadixBits}return b}function reverseStr(a){for(var b="",c=a.length-1;c>-1;--c)b+=a.charAt(c);return b}function biToString(a,b){var c=new BigInt;c.digits[0]=b;for(var d=biDivideModulo(a,c),e=hexatrigesimalToChar[d[1].digits[0]];biCompare(d[0],bigZero)==1;){d=biDivideModulo(d[0],c);digit=d[1].digits[0];e+=hexatrigesimalToChar[d[1].digits[0]]}return(a.isNeg?"-":"")+reverseStr(e)}
+function biToDecimal(a){var b=new BigInt;b.digits[0]=10;for(var c=biDivideModulo(a,b),d=String(c[1].digits[0]);biCompare(c[0],bigZero)==1;){c=biDivideModulo(c[0],b);d+=String(c[1].digits[0])}return(a.isNeg?"-":"")+reverseStr(d)}function digitToHex(a){var b="";for(i=0;i<4;++i){b+=hexToChar[a&15];a>>>=4}return reverseStr(b)}function biToHex(a){var b="";biHighIndex(a);for(var c=biHighIndex(a);c>-1;--c)b+=digitToHex(a.digits[c]);return b}
+function charToHex(a){return a>=48&&a<=57?a-48:a>=65&&a<=90?10+a-65:a>=97&&a<=122?10+a-97:0}function hexToDigit(a){for(var b=0,c=Math.min(a.length,4),d=0;d<c;++d){b<<=4;b|=charToHex(a.charCodeAt(d))}return b}function biFromHex(a){for(var b=new BigInt,c=a.length,d=0;c>0;c-=4,++d)b.digits[d]=hexToDigit(a.substr(Math.max(c-4,0),Math.min(c,4)));return b}
+function biFromString(a,b){var c=a.charAt(0)=="-",d=c?1:0,e=new BigInt,f=new BigInt;f.digits[0]=1;for(var g=a.length-1;g>=d;g--){var h=a.charCodeAt(g);h=charToHex(h);h=biMultiplyDigit(f,h);e=biAdd(e,h);f=biMultiplyDigit(f,b)}e.isNeg=c;return e}function biDump(a){return(a.isNeg?"-":"")+a.digits.join(" ")}
+function biAdd(a,b){var c;if(a.isNeg!=b.isNeg){b.isNeg=!b.isNeg;c=biSubtract(a,b);b.isNeg=!b.isNeg}else{c=new BigInt;for(var d=0,e=0;e<a.digits.length;++e){d=a.digits[e]+b.digits[e]+d;c.digits[e]=d&65535;d=Number(d>=biRadix)}c.isNeg=a.isNeg}return c}
+function biSubtract(a,b){var c;if(a.isNeg!=b.isNeg){b.isNeg=!b.isNeg;c=biAdd(a,b);b.isNeg=!b.isNeg}else{c=new BigInt;var d;for(var e=d=0;e<a.digits.length;++e){d=a.digits[e]-b.digits[e]+d;c.digits[e]=d&65535;if(c.digits[e]<0)c.digits[e]+=biRadix;d=0-Number(d<0)}if(d==-1){for(e=d=0;e<a.digits.length;++e){d=0-c.digits[e]+d;c.digits[e]=d&65535;if(c.digits[e]<0)c.digits[e]+=biRadix;d=0-Number(d<0)}c.isNeg=!a.isNeg}else c.isNeg=a.isNeg}return c}
+function biHighIndex(a){for(var b=a.digits.length-1;b>0&&a.digits[b]==0;)--b;return b}function biNumBits(a){var b=biHighIndex(a);a=a.digits[b];b=(b+1)*bitsPerDigit;var c;for(c=b;c>b-bitsPerDigit;--c){if((a&32768)!=0)break;a<<=1}return c}
+function biMultiply(a,b){for(var c=new BigInt,d,e=biHighIndex(a),f=biHighIndex(b),g,h=0;h<=f;++h){d=0;g=h;for(j=0;j<=e;++j,++g){d=c.digits[g]+a.digits[j]*b.digits[h]+d;c.digits[g]=d&maxDigitVal;d=d>>>biRadixBits}c.digits[h+e+1]=d}c.isNeg=a.isNeg!=b.isNeg;return c}function biMultiplyDigit(a,b){var c,d;result=new BigInt;c=biHighIndex(a);for(var e=d=0;e<=c;++e){d=result.digits[e]+a.digits[e]*b+d;result.digits[e]=d&maxDigitVal;d=d>>>biRadixBits}result.digits[1+c]=d;return result}
+function arrayCopy(a,b,c,d,e){e=Math.min(b+e,a.length);b=b;for(d=d;b<e;++b,++d)c[d]=a[b]}function biShiftLeft(a,b){var c=Math.floor(b/bitsPerDigit),d=new BigInt;arrayCopy(a.digits,0,d.digits,c,d.digits.length-c);c=b%bitsPerDigit;for(var e=bitsPerDigit-c,f=d.digits.length-1,g=f-1;f>0;--f,--g)d.digits[f]=d.digits[f]<<c&maxDigitVal|(d.digits[g]&highBitMasks[c])>>>e;d.digits[0]=d.digits[f]<<c&maxDigitVal;d.isNeg=a.isNeg;return d}
+function biShiftRight(a,b){var c=Math.floor(b/bitsPerDigit),d=new BigInt;arrayCopy(a.digits,c,d.digits,0,a.digits.length-c);c=b%bitsPerDigit;for(var e=bitsPerDigit-c,f=0,g=f+1;f<d.digits.length-1;++f,++g)d.digits[f]=d.digits[f]>>>c|(d.digits[g]&lowBitMasks[c])<<e;d.digits[d.digits.length-1]>>>=c;d.isNeg=a.isNeg;return d}function biMultiplyByRadixPower(a,b){var c=new BigInt;arrayCopy(a.digits,0,c.digits,b,c.digits.length-b);return c}
+function biDivideByRadixPower(a,b){var c=new BigInt;arrayCopy(a.digits,b,c.digits,0,c.digits.length-b);return c}function biModuloByRadixPower(a,b){var c=new BigInt;arrayCopy(a.digits,0,c.digits,0,b);return c}function biCompare(a,b){if(a.isNeg!=b.isNeg)return 1-2*Number(a.isNeg);for(var c=a.digits.length-1;c>=0;--c)if(a.digits[c]!=b.digits[c])return a.isNeg?1-2*Number(a.digits[c]>b.digits[c]):1-2*Number(a.digits[c]<b.digits[c]);return 0}
+function biDivideModulo(a,b){var c=biNumBits(a),d=biNumBits(b),e=b.isNeg,f,g;if(c<d){if(a.isNeg){f=biCopy(bigOne);f.isNeg=!b.isNeg;a.isNeg=false;b.isNeg=false;g=biSubtract(b,a);a.isNeg=true;b.isNeg=e}else{f=new BigInt;g=biCopy(a)}return Array(f,g)}f=new BigInt;g=a;for(var h=Math.ceil(d/bitsPerDigit)-1,l=0;b.digits[h]<biHalfRadix;){b=biShiftLeft(b,1);++l;++d;h=Math.ceil(d/bitsPerDigit)-1}g=biShiftLeft(g,l);c+=l;c=Math.ceil(c/bitsPerDigit)-1;for(d=biMultiplyByRadixPower(b,c-h);biCompare(g,d)!=-1;){++f.digits[c-
+h];g=biSubtract(g,d)}for(c=c;c>h;--c){d=c>=g.digits.length?0:g.digits[c];var m=c-1>=g.digits.length?0:g.digits[c-1],o=c-2>=g.digits.length?0:g.digits[c-2],n=h>=b.digits.length?0:b.digits[h],k=h-1>=b.digits.length?0:b.digits[h-1];f.digits[c-h-1]=d==n?maxDigitVal:Math.floor((d*biRadix+m)/n);for(var p=f.digits[c-h-1]*(n*biRadix+k),q=d*biRadixSquared+(m*biRadix+o);p>q;){--f.digits[c-h-1];p=f.digits[c-h-1]*(n*biRadix|k);q=d*biRadix*biRadix+(m*biRadix+o)}d=biMultiplyByRadixPower(b,c-h-1);g=biSubtract(g,
+biMultiplyDigit(d,f.digits[c-h-1]));if(g.isNeg){g=biAdd(g,d);--f.digits[c-h-1]}}g=biShiftRight(g,l);f.isNeg=a.isNeg!=e;if(a.isNeg){f=e?biAdd(f,bigOne):biSubtract(f,bigOne);b=biShiftRight(b,l);g=biSubtract(b,g)}if(g.digits[0]==0&&biHighIndex(g)==0)g.isNeg=false;return Array(f,g)}function biDivide(a,b){return biDivideModulo(a,b)[0]}function biModulo(a,b){return biDivideModulo(a,b)[1]}function biMultiplyMod(a,b,c){return biModulo(biMultiply(a,b),c)}
+function biPow(a,b){for(var c=bigOne,d=a;;){if((b&1)!=0)c=biMultiply(c,d);b>>=1;if(b==0)break;d=biMultiply(d,d)}return c}function biPowMod(a,b,c){var d=bigOne;a=a;for(b=b;;){if((b.digits[0]&1)!=0)d=biMultiplyMod(d,a,c);b=biShiftRight(b,1);if(b.digits[0]==0&&biHighIndex(b)==0)break;a=biMultiplyMod(a,a,c)}return d}
+function BarrettMu(a){this.modulus=biCopy(a);this.k=biHighIndex(this.modulus)+1;a=new BigInt;a.digits[2*this.k]=1;this.mu=biDivide(a,this.modulus);this.bkplus1=new BigInt;this.bkplus1.digits[this.k+1]=1;this.modulo=BarrettMu_modulo;this.multiplyMod=BarrettMu_multiplyMod;this.powMod=BarrettMu_powMod}
+function BarrettMu_modulo(a){var b=biDivideByRadixPower(a,this.k-1);b=biMultiply(b,this.mu);b=biDivideByRadixPower(b,this.k+1);a=biModuloByRadixPower(a,this.k+1);b=biMultiply(b,this.modulus);b=biModuloByRadixPower(b,this.k+1);a=biSubtract(a,b);if(a.isNeg)a=biAdd(a,this.bkplus1);for(b=biCompare(a,this.modulus)>=0;b;){a=biSubtract(a,this.modulus);b=biCompare(a,this.modulus)>=0}return a}function BarrettMu_multiplyMod(a,b){return this.modulo(biMultiply(a,b))}
+function BarrettMu_powMod(a,b){var c=new BigInt;for(c.digits[0]=1;;){if((b.digits[0]&1)!=0)c=this.multiplyMod(c,a);b=biShiftRight(b,1);if(b.digits[0]==0&&biHighIndex(b)==0)break;a=this.multiplyMod(a,a)}return c};
Please sign in to comment.
Something went wrong with that request. Please try again.