Jump to content

Help for scrambled alphabet site


Hegelund

Recommended Posts

Hi guys!

 

I’m trying to create a site to decrypt a scrambled alphabet.

It has been a while since I coded anything in PHP, so I thought this would be a good excise.

But I’m having trouble getting it to work the way I wanted it. Any help, thoughts?

 

<HTML>
<BODY bgcolor="#E0E0E0">

<h1>Scrambled alphabet</h1>

<?php
if(isset($_POST['save'])){
$a=$_POST["a1"];
$b=$_POST["b1"];
$c=$_POST["c1"];
$d=$_POST["d1"];
$e=$_POST["e1"];
$f=$_POST["f1"];
$g=$_POST["g1"];
$h=$_POST["h1"];
$i=$_POST["i1"];
$j=$_POST["j1"];
$k=$_POST["k1"];
$l=$_POST["l1"];
$m=$_POST["m1"];
$n=$_POST["n1"];
$o=$_POST["o1"];
$p=$_POST["p1"];
$q=$_POST["q1"];
$r=$_POST["r1"];
$s=$_POST["s1"];
$t=$_POST["t1"];
$u=$_POST["u1"];
$v=$_POST["v1"];
$w=$_POST["w1"];
$z=$_POST["z1"];
$y=$_POST["y1"];
$x=$_POST["x1"];
}
?>

<form name="input" action="" method="POST">
<TABLE border="1" cellpadding="1" bgcolor="#B8B8B8">   
<TR>
	<TH></TH>
	<TH>A:</TH>
	<TH>B:</TH>
	<TH>C:</TH>
	<TH>D:</TH>
	<TH>E:</TH>
	<TH>F:</TH>
	<TH>G:</TH>
	<TH>H:</TH>
	<TH>I:</TH>
	<TH>J:</TH>
	<TH>K:</TH>
	<TH>L:</TH>
	<TH>M:</TH>
	<TH>N:</TH>
	<TH>O:</TH>
	<TH>P:</TH>
	<TH>Q:</TH>
	<TH>R:</TH>
	<TH>S:</TH>
	<TH>T:</TH>
	<TH>U:</TH>
	<TH>V:</TH>
	<TH>W:</TH>
	<TH>Z:</TH>
	<TH>Y:</TH>
	<TH>X:</TH>
</TR>
<TR>
	<TH>Character</TH>
	<TD><input name="a1" type="text" size="1" maxlength="1" id="a1" value="<?php if ($_POST) { echo $a; }?>" /></TD>
	<TD><input name="b1" type="text" size="1" maxlength="1" id="b1" value="<?php if ($_POST) { echo $b; }?>" /></TD>
	<TD><input name="c1" type="text" size="1" maxlength="1" id="c1" value="<?php if ($_POST) { echo $c; }?>" /></TD>
	<TD><input name="d1" type="text" size="1" maxlength="1" id="d1" value="<?php if ($_POST) { echo $d; }?>" /></TD>
	<TD><input name="e1" type="text" size="1" maxlength="1" id="e1" value="<?php if ($_POST) { echo $e; }?>" /></TD>
	<TD><input name="f1" type="text" size="1" maxlength="1" id="f1" value="<?php if ($_POST) { echo $f; }?>" /></TD>
	<TD><input name="g1" type="text" size="1" maxlength="1" id="g1" value="<?php if ($_POST) { echo $g; }?>" /></TD>
	<TD><input name="h1" type="text" size="1" maxlength="1" id="h1" value="<?php if ($_POST) { echo $h; }?>" /></TD>
	<TD><input name="i1" type="text" size="1" maxlength="1" id="i1" value="<?php if ($_POST) { echo $i; }?>" /></TD>
	<TD><input name="j1" type="text" size="1" maxlength="1" id="j1" value="<?php if ($_POST) { echo $j; }?>" /></TD>
	<TD><input name="k1" type="text" size="1" maxlength="1" id="k1" value="<?php if ($_POST) { echo $k; }?>" /></TD>
	<TD><input name="l1" type="text" size="1" maxlength="1" id="l1" value="<?php if ($_POST) { echo $l; }?>" /></TD>
	<TD><input name="m1" type="text" size="1" maxlength="1" id="m1" value="<?php if ($_POST) { echo $m; }?>" /></TD>
	<TD><input name="n1" type="text" size="1" maxlength="1" id="n1" value="<?php if ($_POST) { echo $n; }?>" /></TD>
	<TD><input name="o1" type="text" size="1" maxlength="1" id="o1" value="<?php if ($_POST) { echo $o; }?>" /></TD>
	<TD><input name="p1" type="text" size="1" maxlength="1" id="p1" value="<?php if ($_POST) { echo $p; }?>" /></TD>
	<TD><input name="q1" type="text" size="1" maxlength="1" id="q1" value="<?php if ($_POST) { echo $q; }?>" /></TD>
	<TD><input name="r1" type="text" size="1" maxlength="1" id="t1" value="<?php if ($_POST) { echo $r; }?>" /></TD>
	<TD><input name="s1" type="text" size="1" maxlength="1" id="s1" value="<?php if ($_POST) { echo $s; }?>" /></TD>
	<TD><input name="t1" type="text" size="1" maxlength="1" id="t1" value="<?php if ($_POST) { echo $t; }?>" /></TD>
	<TD><input name="u1" type="text" size="1" maxlength="1" id="u1" value="<?php if ($_POST) { echo $u; }?>" /></TD>
	<TD><input name="v1" type="text" size="1" maxlength="1" id="v1" value="<?php if ($_POST) { echo $v; }?>" /></TD>
	<TD><input name="w1" type="text" size="1" maxlength="1" id="w1" value="<?php if ($_POST) { echo $w; }?>" /></TD>
	<TD><input name="z1" type="text" size="1" maxlength="1" id="z1" value="<?php if ($_POST) { echo $z; }?>" /></TD>
	<TD><input name="y1" type="text" size="1" maxlength="1" id="y1" value="<?php if ($_POST) { echo $y; }?>" /></TD>
	<TD><input name="x1" type="text" size="1" maxlength="1" id="x1" value="<?php if ($_POST) { echo $x; }?>" /></TD>
</TR>
</TABLE>
<br />
<form name="input" action="scrambledalphabet.php" method="POST">
<input type="submit" name="save" value="save" />
<input type="reset" name="Cancel" value="Cancel"></TD>
</form>



<br /><br /><br>
<form name="plain" method="POST">
<h4>Encryped String:</h4>
<!--<input type="text" name="code">-->
<textarea name="code" rows="8" cols="76"></textarea>

<br>
<input type="submit" value="DECRYPT">
</form>

<?php 
if ($_POST){
@$plain = $_POST['code'];
$plain = $_POST['code'];
//	$cipher = strtr($plain,  
//		"mgqoafzbcdiehxjklntqrwsuvy#",
//		"abcdefghijklmnopqrstuvwxyz ");
//	echo $cipher;

$real = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "z", "y", "x");
$var = array($a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $s, $t, $u, $v, $w, $z, $y, $x);

$newphrase = str_ireplace($real, $var, $plain);
}
?>
<h4>Dencryped String:</h4> 
<textarea name="code" rows="8" cols="76"><?php echo $newphrase; ?></textarea>
<br /><br /><br>
</BODY>
</HTML>

Link to comment
https://forums.phpfreaks.com/topic/264150-help-for-scrambled-alphabet-site/
Share on other sites

here's my 0.02

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
  <title>Scrambled Alphabet</title>
</head>

<body>
  <h1>Scrambled Alphabet</h1>  
  <form name="input" action="" method="post" id="input">
    <table border="1" cellpadding="1" bgcolor="#B8B8B8">
      <tr>
        <th></th>
        <?php
            for($i=0,$x='A'; $i<26; $i++, $x++) {
                echo "<th>{$x}:</th>"; 
            }
        ?>
      </tr>

      <tr>
        <th>Character</th>
        <?php
            for($i=0; $i<26; $i++) {
                $val = isset($_POST['a'][$i]) ? $_POST['a'][$i] : '';
                echo "<td><input name='a[$i]' type='text' size='1' maxlength='1' value='$val'></td>"; 
            }
            if (isset($_POST['btnSub']))  {
                $real = range('a', 'z');
                $var = $_POST['a'];
                $trans = array_combine($real, $var);
                
                switch ($_POST['btnSub']) {
                case 'Encrypt':
                    $plaintext = $_POST['plaintext'];
                    $crypttext = strtr(strtolower($plaintext), $trans);
                    for ($i=0, $k=strlen($plaintext); $i < $k; $i++) {
                        $c = ord($plaintext[$i]); $d = ord($crypttext[$i]);
                        if (($c & 0x20) != 0x20) $crypttext[$i] = chr($d & 0xDF);
                    }
                    break;
                case 'Decrypt':
                    $trans = array_flip($trans);
                    $crypttext = $_POST['crypttext'];
                    $plaintext = strtr(strtolower($crypttext), $trans);
                    for ($i=0, $k=strlen($plaintext); $i < $k; $i++) {
                        $c = ord($plaintext[$i]); $d = ord($crypttext[$i]);
                        if (($d & 0x20) != 0x20) $plaintext[$i] = chr($c & 0xDF);
                    }
                    break;
                }
                
            }
        ?>
      </tr>
    </table>
    <table>
      <tr>
        <td>Plain text</td>
        <td>Encrypted text</td>
      </tr>
      <tr>
        <td><textarea name="plaintext" cols="60" rows="8"><?php echo $plaintext?></textarea></td>
        <td><textarea name="crypttext" cols="60" rows="8"><?php echo $crypttext?></textarea></td>
      </tr>
      <tr>
        <td><input type="submit" name="btnSub" value="Encrypt"></td>
        <td><input type="submit" name="btnSub" value="Decrypt"></td>
      </tr>
    </table>
  </form>
</body>
</html>                                                            

Am I correct in thinking that what you are trying to do is allow a user to define a secret code such that they can make - for example - A=M, N=E, D=H. where crypted "AND" would output "MEH", and decrypted "MEH" would output "AND"?

 

Yup that was the idea!

 

here's my 0.02

 

Wow - Nice! I need to look a bit deeper into your code to understand how it works, but it looks way smarter then what i slashed together. (and it seems to be working)

 

Thank you very very much!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.