Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function szyfr_cezara_szyfruj($text, $shift)
- {
- $chars_org = array();
- for($i = 65; $i <= 90; $i++)
- {
- $char = chr($i);
- $chars_org[$char] = $char;
- }
- $chars_shifted = array();
- foreach($chars_org as $char)
- {
- $chars_shifted[$char] = chr(65 + (ord($char) - (65 - $shift)) % 26 );
- }
- if ($_POST['crypt'] == "-") {
- $chars_shifted = array_flip($chars_shifted);
- }
- $array = str_split( strtoupper($text) );
- $return = '';
- foreach($array as $item)
- {
- if($item == ' ')
- {
- $return .= ' ';
- }
- else
- {
- echo $item;
- if ($item<'65') {
- $item = '90' - $item;
- }
- $return .= $chars_shifted[$item];
- }
- }
- return $return;
- }
- if (isset($_POST['wyslij'])) {
- if ($_POST['crypt'] == "-") {
- echo "<h2>ODKODOWANIE</h2>";
- echo "Treść do zmiany : ".$_POST['tresc']."<br>";
- echo "Wartość k wyn: ".$_POST['wartosck']."<br>";
- echo "Hasło wynikowe to: ".szyfr_cezara_szyfruj($_POST['tresc'],$_POST['wartosck']);
- }
- else {
- echo "<h2>KODOWANIE</h2>";
- echo "Treść do zmiany : ".$_POST['tresc']."<br>";
- echo "Wartość k wyn: ".$_POST['wartosck']."<br>";
- echo "Hasło wynikowe to: ".szyfr_cezara_szyfruj($_POST['tresc'],$_POST['wartosck']);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement