Sie sind auf Seite 1von 4

#file kunci.

php

<?php

use KKiernan\CaesarCipher;

require dirname(__DIR__).'/vendor/autoload.php';

$cipher = new CaesarCipher();

$plaintext = 'Once upon a midnight dreary, while I pondered, weak and weary,

Over many a quaint and curious volume of forgotten lore,

While I nodded, nearly napping, suddenly there came a tapping,

As of some one gently rapping, rapping at my chamber door.

Tis some visitor," I muttered, "tapping at my chamber door —

Only this, and nothing more.';

$ciphertext = $cipher->encrypt($plaintext, 6);

echo "ENCRYPTED MESSAGE:\n"

."------------------\n"

.$ciphertext

."\n\n";

$keyGuess = $cipher->crack($ciphertext);

echo "BEST GUESS AT KEY:\n"

."------------------\n"

.$keyGuess

."\n\n";

echo "CRACKED MESSAGE ATTEMPT:\n"

."------------------------\n"

.$cipher->decrypt($ciphertext, $keyGuess);
#file prompt.php

<?php

use KKiernan\CaesarCipher;

require dirname(__DIR__).'/vendor/autoload.php';

$continue = true;

$cipher = new CaesarCipher();

/*

|---------------------------------------------------------------------

| Encrypt Message

|---------------------------------------------------------------------

*/

function encrypt()

global $cipher;

echo 'Enter a message: ';

$plaintext = fgets(STDIN);

echo 'Enter a key (1 to 25): ';

$key = fgets(STDIN);

echo "Your encrypted message:\n";

echo $cipher->encrypt($plaintext, $key)."\n";

/*

|---------------------------------------------------------------------

| Crack Ciphertext

|---------------------------------------------------------------------
*/

function crack()

global $cipher;

echo 'Enter an encrypted message: ';

$ciphertext = fgets(STDIN);

$key = $cipher->crack($ciphertext);

echo "\n".$cipher->decrypt($ciphertext, $key);

/*

|---------------------------------------------------------------------

| Main Loop

|---------------------------------------------------------------------

*/

while ($continue) {

echo "Enter an option:\n1. Encrypt\n2. Crack\n3. Exit\n";

$selection = fgets(STDIN);

switch ($selection) {

case 1:

encrypt();

break;

case 2:

crack();

break;

case 3:
$continue = false;

echo 'Goodbye!';

break;

default:

echo "I'm sorry, please select a valid option.\n";

break;

<?php

use KKiernan\CaesarCipher;

require dirname(__DIR__).'/vendor/autoload.php';

$cipher = new CaesarCipher();

$key = 12;

$encrypted = $cipher->encrypt('You\'re two handfuls of soil thrown against the pavement. Why won\'t
you grow?', $key);

echo $encrypted."\n";

$decrypted = $cipher->decrypt($encrypted, $key);

echo $decrypted."\n";

#file simple.php

Das könnte Ihnen auch gefallen