<?php
    
if (isset($_GET['source'])) {
        
highlight_file(__FILE__);
        exit;
    }

    if (!isset(
$_POST['password'])) {
        
?><pre>
<b>Password scrambler</b>
Imagine you want to allow someone to log in, but you do not want them to know
your password because you use it for other things as well. You are not home,
so you need to give them the password before they can log in.

That is where this tool comes in: it obfuscates your password so that you can
give it to the other person, and they can type it in, without knowing what it
was.

Warning: the other person CAN figure out your password, quite easily, if
they <i>want to</i>. You must trust the other person. Also, you must trust this
server (it could store your password). If you do not, copy the <a href="pwd-scrambler.php?source">source code</a>
and run it on your own server (don't forget to use https!).

<form method=post>
The password: <input name=password type=password>

Scrambling:   <input type=number name=scrambling value=2>
              Reasonable is 1 through 4.
              I think 2 or 3 is best.

              <input type=submit value=Scramble>
</form></pre>
            <?php
        
exit;
    }

    
$scrambling intval($_POST['scrambling']);

    
$passwd $_POST['password'];


    if (
strlen($passwd) <= 0) {
        die(
'It does not work without password.');
    }

    if (
strlen($passwd) > 100) {
        die(
'Password too long.');
    }

    if (
$scrambling 20) {
        die(
'Too much scrambling.');
    }

    if (
$scrambling == 0) {
        die(
'Scrambling > 0 please.');
    }

    
$charset '';
    for (
$i ord('0'); $i <= ord('9'); $i++) {
        
$charset .= chr($i);
    }
    for (
$i ord('A'); $i <= ord('Z'); $i++) {
        
$charset .= chr($i);
    }
    for (
$i ord('a'); $i <= ord('z'); $i++) {
        
$charset .= chr($i);
    }
    
$charset .= '!'// Symbol for good measure
    // Some frequently-used characters, more frequently in the scrambled text
    
$charset .= 'e';
    
$charset .= 'e';
    
$charset .= 't';
    
$charset .= 't';
    
$charset .= 'a';
    
$charset .= 'o';
    
$charset .= 'n';
    
$charset .= 'r';
    
$charset .= 'i';

    
$passwdpos 0;
    
$tries 0;

    while (
$passwdpos strlen($passwd)) {
        
$passwdpos 0;
        
$out '';
        
$chance 0;

        for (
$i 0$i strlen($passwd) * $scrambling$i++) {
            
$out .= $charset[mt_rand(0strlen($charset) - 1)];

            if (
mt_rand(0$scrambling 1.25 10) < 13 and $passwdpos strlen($passwd)) {
                
$out .= $passwd[$passwdpos];
                
$passwdpos++;
            }
        }
        
$tries++;

        if (
$tries 100) {
            die(
"Could not find a good scrambling for you. That is odd.");
        }
    }

    
// So it's never the last char
    
for ($i 0$i ceil($scrambling 2); $i++) {
        
$out .= $charset[mt_rand(0strlen($charset) - 1)];
    }

    
$out htmlspecialchars($out);

    echo 
"<!-- $tries try/tries were needed. -->";
    echo 
"<pre>
<b>Instructions for typing the password:</b>
1. Type this in the password field: 
$out
2. Press HOME, or left-arrow until you are at the beginning.
"
;

    
$n 3;
    
$passwdpos 0;
    
$deletes 0;
    for (
$i 0$i strlen($out); $i++) {
        if (
$passwdpos strlen($passwd)) {
            if (
$out[$i] != $passwd[$passwdpos]) {
                
$deletes++;
            }
            else {
                echo 
"$n. Press ${deletes}x delete\n";
                
$deletes 0;
                
$n++;

                echo 
"$n. Press right\n";
                
$passwdpos++;
                
$n++;
            }
        }
    }

    echo 
"$n. Delete until the end.\n\n";
?>
Reload page to re-generate.
If you want to test it, go ahead:
<input type=password size=25 id=p> <input type=button value='Show input' onclick='show();'>
</pre>
<script>
    function show() {
        document.getElementById('p').type = 'text';
    }
</script>