We've made a script. But we don't know how to use it in a HTML page, We tried some things but it doesn't work. The mention is to make a script to translate. Not really translate but like the caesarcode, ( A=B etc.) We want to put the script working on diferent tables. The user can choose the rotation 1 til 25. this is our php 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;
}
}
[/php]
And this is how it has to look like:
[php]
<?php
include 'caesarcodephp.php';
$caesarCode = new CaesarCode( 1 );
$result = $caesarCode->translate( 'ABC' );
?>
<!doctype html>
<html>
<head>
<title>oefen</title>
</head>
<body>
<table border="1">
<tr>
<tr><td>Rotatie:</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>
</select>
</tr>
<tr>
<textarea rows="10" cols="20" style="overflow:hidden;">
<?php echo $caesarCode->translate( 'XYZ' ); ?>
</textarea>
<p style="font-size:10px;"></p>
<textarea rows="10" cols="20" style="overflow:hidden;">
Gecodeerde tekst
</textarea>
<p style="font-size:10px;"></p>
</tr>
<tr>
<td>Resultaat</td>
<td><?php echo $result ?></td>
</tr>
</table>
</body>
</html>
[/php]
I hope you can help us!

Greetz!
Jeanine and Liselotte




