add vigenere chiffere and caeser chiffere by teacher
This commit is contained in:
98
Zweites Jahr/Kryptologie/lehrer_caeser_versch.php
Normal file
98
Zweites Jahr/Kryptologie/lehrer_caeser_versch.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
// GEHT NICHT (richtig)
|
||||
|
||||
function caesar($text, $shift){
|
||||
$result = "";
|
||||
|
||||
for ($i = 0; $i < strlen($text); $i++){
|
||||
$letter = $text[$i];
|
||||
$letter = ord($letter);
|
||||
|
||||
if ($letter > 65 && $letter >= 90){
|
||||
$result .= chr(($letter-65 + $shift) %26 + 65);
|
||||
} elseif ($letter > 97 && $letter >= 122 ) {
|
||||
$result .= chr(($letter-97 + $shift) %26 + 97);
|
||||
} else {
|
||||
$result .=chr($letter);
|
||||
}
|
||||
|
||||
#$result = $letter + $shift %36
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$output = "";
|
||||
$text = "";
|
||||
$shift = 0;
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$text = $_POST["text"] ?? "";
|
||||
$shift = intval($_POST["shift"] ?? 0);
|
||||
|
||||
if (isset($_POST["encrypt"])) {
|
||||
$output = caesar($text, $shift);
|
||||
}
|
||||
|
||||
if (isset($_POST["decrypt"])) {
|
||||
$output = caesar($text, -$shift);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Caesar Chiffre</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background: #f4f4f4;
|
||||
padding: 30px;
|
||||
}
|
||||
.box {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
max-width: 500px;
|
||||
margin: auto;
|
||||
border-radius: 8px;
|
||||
}
|
||||
textarea, input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
button {
|
||||
padding: 10px 20px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
label{
|
||||
display: block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="box">
|
||||
<h2>Caesar Chiffre</h2>
|
||||
|
||||
<form method="post">
|
||||
<label for="text">Nachricht:</label>
|
||||
<textarea name="text" rows="4"><?= htmlspecialchars($text) ?></textarea>
|
||||
|
||||
<label>Verschiebung:</label>
|
||||
<input type="number" name="shift" min = 1 max = 26 value="<?= htmlspecialchars($shift) ?>">
|
||||
<!--<input type="number" name="shift" value="<?= htmlspecialchars($shift) ?>">-->
|
||||
|
||||
<button type="submit" name="encrypt">Verschlüsseln</button>
|
||||
<button type="submit" name="decrypt">Entschlüsseln</button>
|
||||
|
||||
<label for="result"> Verschlüsselte Nachricht:</label>
|
||||
<textarea name="result" rows="4" readonly><?= htmlspecialchars($output ?: $text) ?></textarea>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
99
Zweites Jahr/Kryptologie/vigenere.php
Normal file
99
Zweites Jahr/Kryptologie/vigenere.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
function vigenere($text,$shift){
|
||||
$result = "";
|
||||
|
||||
for ($i = 0; $i < strlen($text); $i++){
|
||||
$shift = $shift[$i%strlen($shift)];
|
||||
$letter = $text[$i];
|
||||
$letter = ord($letter);
|
||||
|
||||
if ($letter > 65 && $letter >= 90){
|
||||
$shift = ord($shift) - 65;
|
||||
$result .= chr(($letter-65 + $shift) %26+ 65);
|
||||
} elseif ($letter > 97 && $letter >= 122 ) {
|
||||
$shift = ord($shift) - 97;
|
||||
$result .= chr(($letter-97 + $shift) %26 + 97);
|
||||
} else {
|
||||
$result .=chr($letter);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$output = "";
|
||||
$text = "";
|
||||
$shift = 0;
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$text = $_POST["text"] ?? "";
|
||||
$shift = $_POST["shift"] ?? 0;
|
||||
|
||||
if (isset($_POST["encrypt"])) {
|
||||
$output = vigenere($text, $shift);
|
||||
}
|
||||
|
||||
if (isset($_POST["decrypt"])) {
|
||||
$output = vigenere($text, -$shift);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Vigenère-Chiffre</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background: #f4f4f4;
|
||||
padding: 30px;
|
||||
}
|
||||
.box {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
max-width: 500px;
|
||||
margin: auto;
|
||||
border-radius: 8px;
|
||||
}
|
||||
textarea, input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
button {
|
||||
padding: 10px 20px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
label{
|
||||
display: block;
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="box">
|
||||
<h2>Vigenère-Chiffre</h2>
|
||||
|
||||
<form method="post">
|
||||
<label for="text">Nachricht:</label>
|
||||
<textarea name="text" rows="4"><?= htmlspecialchars($text) ?></textarea>
|
||||
|
||||
<label>Verschiebung:</label>
|
||||
<input type="text" name="shift" value="<?= htmlspecialchars($shift) ?>">
|
||||
|
||||
<button type="submit" name="encrypt">Verschlüsseln</button>
|
||||
<button type="submit" name="decrypt">Entschlüsseln</button>
|
||||
|
||||
<label for="result"> Verschlüsselte Nachricht:</label>
|
||||
<textarea name="result" rows="4" readonly><?= htmlspecialchars($output ?: $text) ?></textarea>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user