diff --git a/README.md b/README.md index 0feb533..cf981d5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,17 @@ Chiff69 ======= -kids' stuff +Chiff69 is a collection of encryption-algorithms, which use a keylength of 69 bit. + +Because this it made by an amateur __DO NOT__ use this software for any security applications. + + +Chiff69/a +--------- + +This algorithm uses 72 bit to encrypt the text, but the last 3 Bits will be set to 0. This one only uses substitutions. + +Chiff69/b +--------- + +This one uses 64 bit for the substitution (like Chiff69/a). The last 5 bits are used for a rail-fence-cpher-style pre-permutation. diff --git a/chiff69a.php b/chiff69a.php new file mode 100755 index 0000000..5c79d69 --- /dev/null +++ b/chiff69a.php @@ -0,0 +1,69 @@ +#!/usr/bin/php + 3) && ($_SERVER['argv'][3] == "base64") && ($_SERVER['argv'][2] == "decrypt")) + $text = base64_decode($text); + + $tmp = array(); + + for ($i = 0; $i < strlen($text); $i++) { + $tmp[$i] = ord(substr($text, $i, 1)); + } + $text = $tmp; + + $alg = ""; + // we are decrypting + if (($_SERVER['argc'] > 2) && ($_SERVER['argv'][2] == "decrypt")) { + $alg = create_function('$char, $key, $i', 'return (($char - $i) - $key) & 0xff;'); + // we are encrypting + } else { + $alg = create_function('$char, $key, $i', 'return (($char + $key) + $i) & 0xff;'); + } + + $result = array(); + for ($i = 0; $i < count($text); $i++) { + $result[$i] = $alg($text[$i], $key[$i % 5], $i * (2 * ($i % 2) - 1)); + } + + for ($i = 0; $i < count($result); $i++) + $result[$i] = chr($result[$i]); + $result = implode($result); + + if (($_SERVER['argc'] > 3) && ($_SERVER['argv'][3] == "base64") && ($_SERVER['argv'][2] == "encrypt")) + $result = base64_encode($result); + + echo $result . "\n"; +?> diff --git a/chiff69b.php b/chiff69b.php new file mode 100755 index 0000000..8f73fac --- /dev/null +++ b/chiff69b.php @@ -0,0 +1,137 @@ +#!/usr/bin/php + 3) && ($_SERVER['argv'][3] == "base64") && ($_SERVER['argv'][2] == "decrypt")) + $text = base64_decode($text); + + if ($key[4] == 0) + $key[4] = 0x55; + + //$key[4] = 2; + + $tmp = array(); + + if (($_SERVER['argc'] > 2) && ($_SERVER['argv'][2] == "decrypt")) { + for ($i = 0; $i < strlen($text); $i++) { + $tmp[] = $text[$i]; + } + + $text = array(); + + for ($i = 0; $i < count($tmp); $i++) { + $text[] = $tmp[$i]; + } + } else { + for ($i = 0; $i < $key[4]; $i++) + $tmp[$i] = array(); + + for ($i = 0; $i < strlen($text); $i++) { + $tmp[$i % $key[4]][] = $text[$i]; + } + + $max = 0; + + for($i = 0; $i < count($tmp); $i++) { + if (count($tmp[$i]) > $max) { + $max = count($tmp[$i]); + $i = 0; + continue; + } + while (count($tmp[$i]) < $max) { + $tmp[$i][] = " "; + } + } + + $text = array(); + + for ($i = 0; $i < count($tmp); $i++) + for ($j = 0; $j < count($tmp[$i]); $j++) + $text[] = $tmp[$i][$j]; + } + + + + $tmp = array(); + + for ($i = 0; $i < count($text); $i++) { + $tmp[$i] = ord($text[$i]); + } + $text = $tmp; + + $alg = ""; + // we are decrypting + if (($_SERVER['argc'] > 2) && ($_SERVER['argv'][2] == "decrypt")) { + $alg = create_function('$char, $key, $i', 'return (($char - $i) - $key) & 0xff;'); + // we are encrypting + } else { + $alg = create_function('$char, $key, $i', 'return (($char + $key) + $i) & 0xff;'); + } + + $result = array(); + for ($i = 0; $i < count($text); $i++) { + $result[$i] = $alg($text[$i], $key[$i % 4], $i * (2 * ($i % 2) - 1)); + } + + for ($i = 0; $i < count($result); $i++) + $result[$i] = chr($result[$i]); + + if (($_SERVER['argc'] > 2) && ($_SERVER['argv'][2] == "decrypt")) { + $tmp = array(); + for ($i = 0; $i < $key[4]; $i++) + $tmp[$i] = array(); + + for ($i = 0; $i < count($result); $i++) { + $a = (count($result) / $key[4]); + $b = $i % ceil($a); + $tmp[intval($b)][] = $result[$i]; + } + + $result = array(); + + for ($i = 0; $i < count($tmp); $i++) + for ($j = 0; $j < count($tmp[$i]); $j++) + $result[] = $tmp[$i][$j]; + } + + $result = implode($result); + + if (($_SERVER['argc'] > 3) && ($_SERVER['argv'][3] == "base64") && ($_SERVER['argv'][2] == "encrypt")) + $result = base64_encode($result); + + echo $result . "\n"; +?>