Compare commits

...

2 Commits

Author SHA1 Message Date
Eirik Th S e91e508e6b [WIP] Modul 5 oppgave 5 2021-10-22 11:07:43 +02:00
Eirik Th S 49ea939196 Dark-mode. (Kan deaktiveres med class .light på <body>) 2021-10-18 20:01:45 +02:00
6 changed files with 98 additions and 4 deletions

View File

@ -11,9 +11,9 @@ if ! [ -d "modul$modulnr" ]; then
mkdir modul$modulnr
cd modul$modulnr
cp -s ../modul1/index.css ./
#cp -s ../modul1/index.css ./
cp -s ../modul1/index.php ./
cp -s ../modul1/common.php ./
#cp -s ../modul1/common.php ./
cp ../mal.php "./index$(echo $modulnr)_1.php"
echo "OK"

View File

@ -1,8 +1,22 @@
body {
text-align: center;
font-family: sans-serif;
background-color: #181818;
/*color: #ede8e8;*/
color: #dbd8d3;
}
body.light {
background-color: #fff;
color: #222;
}
body.light a {
color: unset;
}
a {
color: #de732e;
}
.container {
max-width: 900px;

View File

@ -2,6 +2,7 @@
<html lang="no">
<head>
<title>IS-115 - Webprogrammering i PHP</title>
<link rel="stylesheet" href="index.css">
<style>
body {
text-align: center;

View File

@ -1,8 +1,8 @@
<?php include 'common.php'; ?><!DOCTYPE html>
<?php include '../common.php'; ?><!DOCTYPE html>
<html lang="no">
<head>
<title><?=title();?></title>
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="../index.css">
</head>
<body>

1
modul5/index.php Symbolic link
View File

@ -0,0 +1 @@
../modul1/index.php

78
modul5/index5_5.php Normal file
View File

@ -0,0 +1,78 @@
<?php include '../common.php'; ?><!DOCTYPE html>
<html lang="no">
<head>
<title><?=title();?></title>
<link rel="stylesheet" href="../index.css">
</head>
<body>
<div class="container">
<h1><?=title();?></h1>
<h4><?=getNavigation();?></h4>
<h2>Kryptering</h2>
<?php
$input = $_POST['input'] ?? 'standard påstand';
$output = $_POST['output'] ?? '';
$randoms = "!#%&/()=?+*-:;";
$asciiKoder = array(); // liste med 'godkjente' ascii koder som de kan rotere på.
function krypter($input): String {
// Array med alle tegn i den insatte strengen.
$karakterer = preg_split('//u', $input, null, PREG_SPLIT_NO_EMPTY);
// Flytte på alle karakterene med 2/3-deler.
$karakterer = arrayMove($karakterer, 2/3);
// gjøre hvert tegn om til ascii-tall med mb_ord
// forskyve tallene til +30 per $asciiKoder
// sette inn tilfeldige random-tegn annenhvert tegn
foreach ($karakterer as &$tegn){
// echo $tegn.": ".mb_ord($tegn)."<br>\n";
$tegn = mb_ord($tegn);
}
unset($tegn);
return implode($karakterer);
}
function dekrypter($input): string {
// Array med alle tegn i den insatte strengen.
$karakterer = preg_split('//u', $input, null, PREG_SPLIT_NO_EMPTY);
$karakterer = arrayMove($karakterer, 1/3);
return $input;
}
// Rotere nøklene på en array med en satt forskyvning.
function arrayMove($array, $forskyvning = 2/3): array {
$len = count($array);
$start = round($len*$forskyvning);
$ut = array();
foreach ($array as $value){
$ut[$start] = $value;
$start++;
if($start>=$len){
$start = 0;
}
}
ksort($ut);
return $ut;
}
echo "<p>Ukryptert: <textarea>".$input."</textarea></p>";
echo "<p>Kryptert: <textarea>".krypter($input)."</textarea></p>";
?>
</div>
</body>
</html>