Jump to content

Code in textfield Caesarcode


JenL

Recommended Posts

Hello everyone,

 

We have written a code to make a translator of the Caesarcode. But we don't know how we put the code working on the textfield. We tried by ourselves but it doesn't work. So we are asking where and which code we have to put in to the html textfield. This is our code:

<?php

 

class CaesarCode {

    private static $alfabetUpper;

    private static $alfabetLower;

   

    private $steps;

   

    private function _getNewPosition($originalPosition) {

        return ($originalPosition + $this->steps) % 26;

    }

   

    private function _getCharFromArray($char, $fromArray) {

        if (($charKey = array_search($char, $fromArray)) !== false) {

            return $fromArray[$this->_getNewPosition($charKey)];

        }

        return false;

    }

   

    private function _translateChar($char) {

        $translatedChar = $this->_getCharFromArray($char, $this->_getAlfabetUpper());

        if ($translatedChar === false) {

            $translatedChar = $this->_getCharFromArray($char, $this->_getAlfabetLower());

        }

        return $translatedChar;

    }

   

    private function _getAlfabetUpper() {

        if (empty(self::$alfabetUpper)) {

            self::$alfabetUpper = range('A', 'Z');

        }

        return self::$alfabetUpper;

    }

   

    private function _getAlfabetLower() {

        if (empty(self::$alfabetLower)) {

            self::$alfabetLower = range('a', 'z');

        }

        return self::$alfabetLower;

    }

   

    public function __construct($steps) {

        $this->steps = $steps;

    }

   

    public function translate($string) {

        $encr = '';

        foreach (str_split($string) as $key => $char) {

            if (($newChar = $this->_translateChar($char)) !== false)

                $char = $newChar;

            $encr .= $char;

        }

        return $encr;

    }

}

?>

 

 

And this is the html code:

 

<?php

// de class CaesarCode beschikbaar maken in dit bestand

include 'caesarcodephp.php';

$caesarCode = new CaesarCode( 1 );

// de uitkomst opslaan in de variabele $result

$result = $caesarCode->translate( 'ABC' );

?>

<!doctype html>

<html>

  <head>

    <title>oefen</title>

  </head>

  <body>

    <table border="1">

      <tr>

        <tr><td>Rotation:</td>

<td>

<select>

  <option value ="1"><?php $caesarCode= new CaesarCode( 1 ); ?> 1 </option>

  <option value ="2"><?php $caesarCode= new CaesarCode( 2 ); ?>2

</option>

  <option value ="3"><?php $caesarCode= new CaesarCode( 3 ); ?>3</option>

  <option value ="4"><?php $caesarCode= new CaesarCode( 4 ); ?>4</option> 

  <option value ="5">5</option>

  <option value ="6">6</option>

  <option value ="7">7</option> 

  <option value ="8">8</option>

  <option value ="9">9</option>

  <option value ="10">10</option>

  </select>

      </tr>

      <tr>

        <textarea rows="10" cols="20" style="overflow:hidden;">

<?php echo $caesarCode->translate( 'XYZ' ); ?> INPUT TEXT??

</textarea>

<p style="font-size:10px;"></p>

      <textarea rows="10" cols="20" style="overflow:hidden;">

Output text</textarea>

<p style="font-size:10px;"></p>

      </tr>

      <tr>

        <td>Result</td>

        <td><?php echo $result ?></td>

      </tr>

    </table>

  </body>

</html>

 

Thank you very much!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.